| 2347 | } |
| 2348 | |
| 2349 | void UseArraysExtraInfo(Model* model, bool quantize_output) { |
| 2350 | for (const auto& entry : model->flags.arrays_extra_info().entries()) { |
| 2351 | const auto matches = ScanArrayNames(*model, entry); |
| 2352 | for (const auto& matched_name : matches) { |
| 2353 | auto& array = model->GetArray(matched_name); |
| 2354 | if (entry.has_min() || entry.has_max()) { |
| 2355 | CHECK_EQ(entry.has_min(), entry.has_max()); |
| 2356 | auto& minmax = array.GetOrCreateMinMax(); |
| 2357 | minmax.min = entry.min(); |
| 2358 | minmax.max = entry.max(); |
| 2359 | } |
| 2360 | if (entry.has_data_type() && quantize_output) { |
| 2361 | array.final_data_type = |
| 2362 | ConvertIODataTypeToArrayDataType(entry.data_type()); |
| 2363 | } |
| 2364 | if (entry.has_shape()) { |
| 2365 | array.clear_shape(); |
| 2366 | // Make sure to create the shape even if there are no dims, to |
| 2367 | // correctly record 0-D shapes. |
| 2368 | array.mutable_shape(); |
| 2369 | for (const auto& dim : entry.shape().dims()) { |
| 2370 | array.mutable_shape()->mutable_dims()->push_back(dim); |
| 2371 | } |
| 2372 | } |
| 2373 | if (entry.has_constant_float_value()) { |
| 2374 | CHECK(array.has_shape()); |
| 2375 | if (array.data_type == ArrayDataType::kFloat) { |
| 2376 | auto& data = array.GetMutableBuffer<ArrayDataType::kFloat>().data; |
| 2377 | data.resize(RequiredBufferSizeForShape(array.shape())); |
| 2378 | for (float& f : data) { |
| 2379 | f = entry.constant_float_value(); |
| 2380 | } |
| 2381 | } |
| 2382 | } |
| 2383 | } |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | void UndoWeightsShuffling(Model* model) { |
| 2388 | for (const auto& op : model->operators) { |
no test coverage detected