| 1207 | } |
| 1208 | |
| 1209 | tensorflow::Status ConvertMaxPoolOperator( |
| 1210 | const NodeDef& node, const TensorFlowImportFlags& tf_import_flags, |
| 1211 | const ModelFlags& model_flags, Model* model) { |
| 1212 | CHECK_EQ(node.op(), "MaxPool"); |
| 1213 | TF_QCHECK_OK(CheckInputsCount(node, tf_import_flags, 1)); |
| 1214 | const auto& input_name = node.input(0); |
| 1215 | // We only support NHWC, which is the default data_format. |
| 1216 | // So if data_format is not defined, we're all good. |
| 1217 | if (node.attr().count("data_format")) { |
| 1218 | CHECK_EQ(GetStringAttr(node, "data_format"), "NHWC"); |
| 1219 | } |
| 1220 | if (HasAttr(node, "T")) { |
| 1221 | CHECK_EQ(GetDataTypeAttr(node, "T"), DT_FLOAT); |
| 1222 | } else { |
| 1223 | LOG(WARNING) << "Found MaxPool operator missing 'T' attribute"; |
| 1224 | } |
| 1225 | auto* maxpool = new MaxPoolOperator; |
| 1226 | maxpool->inputs.push_back(input_name); |
| 1227 | maxpool->outputs.push_back(node.name()); |
| 1228 | const auto& strides = GetListAttr(node, "strides"); |
| 1229 | CHECK_EQ(strides.i_size(), 4); |
| 1230 | CHECK_EQ(strides.i(0), 1); |
| 1231 | CHECK_EQ(strides.i(3), 1); |
| 1232 | maxpool->stride_height = strides.i(1); |
| 1233 | maxpool->stride_width = strides.i(2); |
| 1234 | const auto& ksize = GetListAttr(node, "ksize"); |
| 1235 | CHECK_EQ(ksize.i_size(), 4); |
| 1236 | CHECK_EQ(ksize.i(0), 1); |
| 1237 | CHECK_EQ(ksize.i(3), 1); |
| 1238 | maxpool->kheight = ksize.i(1); |
| 1239 | maxpool->kwidth = ksize.i(2); |
| 1240 | const auto& padding = GetStringAttr(node, "padding"); |
| 1241 | if (padding == "SAME") { |
| 1242 | maxpool->padding.type = PaddingType::kSame; |
| 1243 | } else if (padding == "VALID") { |
| 1244 | maxpool->padding.type = PaddingType::kValid; |
| 1245 | } else { |
| 1246 | LOG(FATAL) << "Bad padding (only SAME and VALID are supported)"; |
| 1247 | } |
| 1248 | model->operators.emplace_back(maxpool); |
| 1249 | return tensorflow::Status::OK(); |
| 1250 | } |
| 1251 | |
| 1252 | tensorflow::Status ConvertAvgPoolOperator( |
| 1253 | const NodeDef& node, const TensorFlowImportFlags& tf_import_flags, |
nothing calls this directly
no test coverage detected