1d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower/* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 3d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlowerLicensed under the Apache License, Version 2.0 (the "License"); 4d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 5d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlowerYou may obtain a copy of the License at 6d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 7d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower http://www.apache.org/licenses/LICENSE-2.0 8d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 9d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlowerUnless required by applicable law or agreed to in writing, software 10d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlowerdistributed under the License is distributed on an "AS IS" BASIS, 11d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlowerWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlowerSee the License for the specific language governing permissions and 13d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlowerlimitations under the License. 14d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower==============================================================================*/ 15d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 16d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower#include "tensorflow/core/framework/node_def_builder.h" 17d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower#include "tensorflow/core/framework/op.h" 18d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower#include "tensorflow/core/framework/shape_inference_testutil.h" 19d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower#include "tensorflow/core/framework/tensor_testutil.h" 20cf93b043a88607db17b84b5b5d3f0064473cf5ceA. Unique TensorFlower#include "tensorflow/core/lib/core/status_test_util.h" 21d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower#include "tensorflow/core/platform/test.h" 22d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 23d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlowernamespace tensorflow { 24d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 25d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlowerTEST(ImageOpsTest, SampleDistortedBoundingBox_ShapeFn) { 26d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower ShapeInferenceTestOp op("SampleDistortedBoundingBox"); 27d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "?;?", "[3];[3];[1,1,4]"); 28d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower} 29d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 30d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlowerTEST(ImageOpsTest, Resize_ShapeFn) { 31d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower for (const char* op_name : {"ResizeArea", "ResizeBicubic", "ResizeBilinear", 32d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower "ResizeNearestNeighbor"}) { 33d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower ShapeInferenceTestOp op(op_name); 34d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower op.input_tensors.resize(2); 35d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 36d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // Inputs are images and size. 37d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 38d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // Rank and size checks. 39d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Shape must be rank 4 but is rank 5", op, "[1,2,3,4,5];?"); 40d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Shape must be rank 4 but is rank 3", op, "[1,2,3];?"); 41d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Shape must be rank 1 but is rank 0", op, "?;[]"); 42d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Dimension must be 2 but is 3", op, "?;[3]"); 43d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 44d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // When the size tensor is not a constant, the middle dims are unknown. 45d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "[1,?,3,?];[2]", "[d0_0,?,?,d0_3]"); 46d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 47d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower Tensor size_tensor = test::AsTensor<int32>({20, 30}); 48d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower op.input_tensors[1] = &size_tensor; 49d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "[1,?,3,?];[2]", "[d0_0,20,30,d0_3]"); 50d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower } 51d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower} 52d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 538016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlowerTEST(ImageOpsTest, DecodeGif) { 548016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower ShapeInferenceTestOp op("DecodeGif"); 558016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower 568016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower // Rank check. 578016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower INFER_ERROR("Shape must be rank 0 but is rank 1", op, "[1]"); 588016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower 598016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower // Output is always ?,?,?,3. 608016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower INFER_OK(op, "?", "[?,?,?,3]"); 618016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower INFER_OK(op, "[]", "[?,?,?,3]"); 628016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower} 638016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower 64d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlowerTEST(ImageOpsTest, DecodeImage_ShapeFn) { 65d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower for (const char* op_name : {"DecodeJpeg", "DecodePng"}) { 66d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower ShapeInferenceTestOp op(op_name); 67d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 68d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // Rank check. 69d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Shape must be rank 0 but is rank 1", op, "[1]"); 70d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 71660d7e5ae51d8d74643874b9ae10f855dced69bbA. Unique TensorFlower // Set the channel to zero - output is not known. 72660d7e5ae51d8d74643874b9ae10f855dced69bbA. Unique TensorFlower TF_ASSERT_OK(NodeDefBuilder("test", op_name) 73660d7e5ae51d8d74643874b9ae10f855dced69bbA. Unique TensorFlower .Input({"a", 0, DT_STRING}) 74660d7e5ae51d8d74643874b9ae10f855dced69bbA. Unique TensorFlower .Finalize(&op.node_def)); 75d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "[]", "[?,?,?]"); 76d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 77d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // Set the channel and so that part of output shape is known. 78cf93b043a88607db17b84b5b5d3f0064473cf5ceA. Unique TensorFlower TF_ASSERT_OK(NodeDefBuilder("test", op_name) 79cf93b043a88607db17b84b5b5d3f0064473cf5ceA. Unique TensorFlower .Input({"a", 0, DT_STRING}) 80cf93b043a88607db17b84b5b5d3f0064473cf5ceA. Unique TensorFlower .Attr("channels", 4) 81cf93b043a88607db17b84b5b5d3f0064473cf5ceA. Unique TensorFlower .Finalize(&op.node_def)); 82d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "[]", "[?,?,4]"); 83d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 84d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // Negative channel value is rejected. 85cf93b043a88607db17b84b5b5d3f0064473cf5ceA. Unique TensorFlower TF_ASSERT_OK(NodeDefBuilder("test", op_name) 86cf93b043a88607db17b84b5b5d3f0064473cf5ceA. Unique TensorFlower .Input({"a", 0, DT_STRING}) 87cf93b043a88607db17b84b5b5d3f0064473cf5ceA. Unique TensorFlower .Attr("channels", -1) 88cf93b043a88607db17b84b5b5d3f0064473cf5ceA. Unique TensorFlower .Finalize(&op.node_def)); 89d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("channels must be non-negative, got -1", op, "[]"); 90d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower } 91d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower} 92d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 939d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing TanTEST(ImageOpsTest, DecodeAndCropJpeg_ShapeFn) { 949d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan const char* op_name = "DecodeAndCropJpeg"; 959d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan ShapeInferenceTestOp op(op_name); 969d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan 979d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan // Check the number of inputs. 989d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan INFER_ERROR("Wrong number of inputs passed: 1 while 2 expected", op, "[1]"); 999d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan 1009d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan // Rank check. 1019d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan INFER_ERROR("Shape must be rank 0 but is rank 1", op, "[1];?"); 1029d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan 1039d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan // Set the channel to zero - output is not known. 1049d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan TF_ASSERT_OK(NodeDefBuilder("test", op_name) 1059d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan .Input({"img", 0, DT_STRING}) 1069d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan .Input({"crop_window", 1, DT_INT32}) 1079d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan .Finalize(&op.node_def)); 108568127ac3b8e501bb230ee287ec9a46129fad349Yong Tang INFER_OK(op, "[];[?]", "[?,?,?]"); 1099d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan 1109d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan // Set the channel, so that part of output shape is known. 1119d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan TF_ASSERT_OK(NodeDefBuilder("test", op_name) 1129d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan .Input({"img", 0, DT_STRING}) 1139d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan .Input({"crop_window", 1, DT_INT32}) 1149d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan .Attr("channels", 4) 1159d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan .Finalize(&op.node_def)); 116568127ac3b8e501bb230ee287ec9a46129fad349Yong Tang INFER_OK(op, "[];[?]", "[?,?,4]"); 1179d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan 1189d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan // Negative channel value is rejected. 1199d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan TF_ASSERT_OK(NodeDefBuilder("test", op_name) 1209d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan .Input({"img", 0, DT_STRING}) 1219d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan .Input({"crop_window", 1, DT_INT32}) 1229d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan .Attr("channels", -1) 1239d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan .Finalize(&op.node_def)); 1249d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan INFER_ERROR("channels must be non-negative, got -1", op, "[];[]"); 1259d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan} 1269d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan 1279d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing TanTEST(ImageOpsTest, DecodeAndCropJpeg_InvalidCropWindow) { 1289d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan const char* op_name = "DecodeAndCropJpeg"; 1299d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan ShapeInferenceTestOp op(op_name); 1309d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan 1319d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan // Check the number of inputs. 1329d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan INFER_ERROR("Wrong number of inputs passed: 1 while 2 expected", op, "[1]"); 1339d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan 1349d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan // Rank check. 1359d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan INFER_ERROR("Shape must be rank 0 but is rank 1", op, "[1];?"); 1369d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan 1379d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan // Set the channel to zero - output is not known. 1389d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan TF_ASSERT_OK(NodeDefBuilder("test", op_name) 1399d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan .Input({"img", 0, DT_STRING}) 1409d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan .Input({"crop_window", 1, DT_INT32}) 1419d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan .Finalize(&op.node_def)); 142568127ac3b8e501bb230ee287ec9a46129fad349Yong Tang INFER_OK(op, "[];[?]", "[?,?,?]"); 1439d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan} 1449d56f419cf3a92fb4c66943f216d3632c940b9dbMingxing Tan 145d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlowerTEST(ImageOpsTest, EncodeImage_ShapeFn) { 146d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower for (const char* op_name : {"EncodeJpeg", "EncodePng"}) { 147d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower ShapeInferenceTestOp op(op_name); 148d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 149d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // Rank check. 150d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Shape must be rank 3 but is rank 2", op, "[1,2]"); 151d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 152d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "[1,?,3]", "[]"); // output is always scalar. 153d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower } 154d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower} 155d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 1560599901f020dd2e74b93bc4e12364027fbde1f1cMingxing TanTEST(ImageOpsTest, ExtractJpegShape_ShapeFn) { 1570599901f020dd2e74b93bc4e12364027fbde1f1cMingxing Tan ShapeInferenceTestOp op("ExtractJpegShape"); 1580599901f020dd2e74b93bc4e12364027fbde1f1cMingxing Tan 1590599901f020dd2e74b93bc4e12364027fbde1f1cMingxing Tan // Rank check. 1600599901f020dd2e74b93bc4e12364027fbde1f1cMingxing Tan INFER_ERROR("Shape must be rank 0 but is rank 1", op, "[1]"); 1610599901f020dd2e74b93bc4e12364027fbde1f1cMingxing Tan 1620599901f020dd2e74b93bc4e12364027fbde1f1cMingxing Tan // Only specify input data. Output must be a 1-D tensor with 3 elements. 1630599901f020dd2e74b93bc4e12364027fbde1f1cMingxing Tan INFER_OK(op, "?", "[3]"); 1640599901f020dd2e74b93bc4e12364027fbde1f1cMingxing Tan} 1650599901f020dd2e74b93bc4e12364027fbde1f1cMingxing Tan 166d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlowerTEST(ImageOpsTest, Colorspace_ShapeFn) { 167d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower for (const char* op_name : {"HSVToRGB", "RGBToHSV"}) { 168d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower ShapeInferenceTestOp op(op_name); 169d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 170d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // Rank check. 171d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Shape must be at least rank 1 but is rank 0", op, "[]"); 172d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 173d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // Input's last dim is required to be 3. 174d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Dimension must be 3 but is 4", op, "[1,2,4]"); 175d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "[1,2,3]", "[d0_0,d0_1,d0_2]"); 176d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "[1,2,?]", "[d0_0,d0_1,3]"); 177d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "?", "?"); 178d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower } 179d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower} 180d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 181d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlowerTEST(ImageOpsTest, ExtractGlimpse_ShapeFn) { 182d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower ShapeInferenceTestOp op("ExtractGlimpse"); 183d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower op.input_tensors.resize(2); 184d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 185d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // Inputs are input, size, offsets. 186d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 187d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // Rank and size checks. 188d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Shape must be rank 4 but is rank 5", op, "[1,2,3,4,5];?;?"); 189d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Shape must be rank 4 but is rank 3", op, "[1,2,3];?;?"); 190d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Shape must be rank 1 but is rank 0", op, "?;[];?"); 191d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Dimension must be 2 but is 3", op, "?;[3];?"); 192d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Shape must be rank 2 but is rank 3", op, "?;?;[1,2,3]"); 193d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 194d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // When the size tensor is not a constant, the middle dims are unknown. 195d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "[1,?,3,?];[2];?", "[d0_0,?,?,d0_3]"); 196d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 197d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower Tensor size_tensor = test::AsTensor<int32>({20, 30}); 198d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower op.input_tensors[1] = &size_tensor; 199d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "[1,?,3,?];[2];?", "[d0_0,20,30,d0_3]"); 200d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 201d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // input.dim(0) and offsets.dim(0) are both the batch dimension. 202d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "[?,?,3,?];[2];[1,?]", "[d2_0,20,30,d0_3]"); 203d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "[1,?,3,?];[2];[1,?]", "[d0_0|d2_0,20,30,d_0|d0_3]"); 204d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Dimensions must be equal, but are 10 and 1", op, 205d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower "[10,?,?,?];?;[1,2]"); 206d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower} 207d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 208d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlowerTEST(ImageOpsTest, CropAndResize_ShapeFn) { 209d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower ShapeInferenceTestOp op("CropAndResize"); 210d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower op.input_tensors.resize(4); 211d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 212d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // Inputs are: input, boxes, box_ind, and crop_size. 213d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 214d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // Rank and size checks. 215d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Shape must be rank 4 but is rank 5", op, "[1,2,3,4,5];?;?;?"); 216d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Shape must be rank 4 but is rank 3", op, "[1,2,3];?;?;?"); 217d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Shape must be rank 2 but is rank 3", op, "?;[1,2,3];?;?"); 21894ca4efbb27cf78bb012e418712cf14d36dea4d0A. Unique TensorFlower INFER_ERROR("Shape must be rank 1 but is rank 2", op, "?;?;[1,2];?"); 219d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Shape must be rank 1 but is rank 2", op, "?;?;?;[1,2]"); 220d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Dimension must be 2 but is 1", op, "?;?;?;[1]"); 221d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 222d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // When the size tensor is not a constant, the middle dims are unknown. 223d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "[1,?,3,?];?;?;[2]", "[?,?,?,d0_3]"); 224d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 225d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower Tensor size_tensor = test::AsTensor<int32>({20, 30}); 226d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower op.input_tensors[3] = &size_tensor; 22794ca4efbb27cf78bb012e418712cf14d36dea4d0A. Unique TensorFlower INFER_OK(op, "[1,?,3,?];?;?;[2]", "[?,20,30,d0_3]"); 228d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 229d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // boxes.dim(0) and box_ind.dim(0) are both the num_boxes dim. 230d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "[1,?,3,?];[2,4];?;[2]", "[d1_0,20,30,d0_3]"); 231d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "[1,?,3,?];?;[2];[2]", "[d2_0,20,30,d0_3]"); 232d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_OK(op, "[1,?,3,?];[?,4];[?];[2]", "[d1_0|d3_0,20,30,d0_3]"); 233d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Dimensions must be equal, but are 2 and 1", op, "?;[2,?];[1];?"); 234d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 235d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower // boxes.dim(1) must be 4. 236d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower INFER_ERROR("Dimension must be 4 but is 3", op, "?;[?,3];?;?"); 237d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower} 238d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower 239d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh SivakumarTEST(ImageOpsTest, ResizeNearestNeighborGrad_ShapeFn) { 240d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar ShapeInferenceTestOp op("ResizeNearestNeighborGrad"); 241d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar op.input_tensors.resize(2); 242d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar 243d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar // Rank and size checks. 244d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar INFER_ERROR("Shape must be rank 4 but is rank 3", op, "[1,2,3];?"); 245d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar INFER_ERROR("Shape must be rank 1 but is rank 2", op, "?;[1,2]") 246d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar INFER_ERROR("Dimension must be 2 but is 1", op, "?;[1]"); 247d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar 248d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar // When the size tensor is not a constant, the middle dims are unknown. 249d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar INFER_OK(op, "[1,?,3,?];[2]", "[d0_0,?,?,d0_3]"); 250d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar 251d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar Tensor size_tensor = test::AsTensor<int32>({20, 30}); 252d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar op.input_tensors[1] = &size_tensor; 253d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar INFER_OK(op, "[1,?,3,?];[2]", "[d0_0,20,30,d0_3]"); 254d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar} 255d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar 256d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh SivakumarTEST(ImageOpsTest, CropAndResizeGradImage_ShapeFn) { 257d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar ShapeInferenceTestOp op("CropAndResizeGradImage"); 258d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar op.input_tensors.resize(4); 259d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar 260d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar // Rank checks. 261d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar INFER_ERROR("Shape must be rank 1 but is rank 2", op, "?;?;?;[1,2]"); 262d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar 263d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar // Unknown image_size should result in output of rank 4 with unknown dims. 264d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar INFER_OK(op, "?;?;?;?", "[?,?,?,?]"); 265d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar 266d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar // Known image_size should result in full shape information. 267d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar Tensor image_size = test::AsTensor<int32>({10, 20, 30, 40}); 268d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar op.input_tensors[3] = &image_size; 269d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar INFER_OK(op, "?;?;?;[1]", "[10, 20, 30, 40]"); 270d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar} 271d55d69a633af9d0e38726e2cdf2504b9e269a3f8Suharsh Sivakumar 2728016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlowerTEST(ImageOpsTest, RandomCrop_ShapeFn) { 2738016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower ShapeInferenceTestOp op("RandomCrop"); 2748016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower op.input_tensors.resize(2); 2758016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower 2768016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower // Rank checks. 2778016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower INFER_ERROR("must be rank 3", op, "[1,2];?"); 2788016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower INFER_ERROR("must be equal", op, "?;[3]"); 2798016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower INFER_ERROR("must be equal", op, "?;[1,2]"); 2808016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower 2818016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower // Unknown size tensor values. 2828016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower INFER_OK(op, "[?,?,?];[2]", "[?,?,d0_2]"); 2838016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower 2848016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower // Known size should result in full shape information. 2858016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower Tensor size = test::AsTensor<int64>({10, 20}); 2868016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower op.input_tensors[1] = &size; 2878016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower INFER_OK(op, "[?,?,?];[2]", "[10,20,d0_2]"); 2888016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower} 2898016cf4ab1e2ff3c3c5448e539b9ec89d5a0bcd4A. Unique TensorFlower 2908928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlowerTEST(ImageOpsTest, QuantizedResizeBilinear_ShapeFn) { 2918928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower ShapeInferenceTestOp op("QuantizedResizeBilinear"); 2928928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower op.input_tensors.resize(4); 2938928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower 2948928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower NodeDefBuilder builder = 2958928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower NodeDefBuilder("test", "QuantizedResizeBilinear") 2968928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower .Input(NodeDefBuilder::NodeOut{"images", 0, DT_QINT32}) 2978928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower .Input(NodeDefBuilder::NodeOut{"size", 0, DT_INT32}) 2988928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower .Input(NodeDefBuilder::NodeOut{"min", 0, DT_FLOAT}) 2998928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower .Input(NodeDefBuilder::NodeOut{"max", 0, DT_FLOAT}) 3008928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower .Attr("T", DT_QINT32) 3018928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower .Attr("Toutput", DT_QINT32); 3028928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower TF_ASSERT_OK(builder.Finalize(&op.node_def)); 3038928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower 3048928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower // When the size tensor is not a constant, the middle dims are unknown. 3058928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower INFER_OK(op, "[1,?,3,?];[2];[];[]", 3068928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower "[d0_0,?,?,d0_3];[];[]"); // output rank unknown 3078928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower INFER_ERROR("must be rank 0", op, "[1,?,3,?];[2];[?];[]"); 3088928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower INFER_ERROR("must be rank 0", op, "[1,?,3,?];[2];[];[?]"); 3098928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower 3108928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower const Tensor size_tensor = test::AsTensor<int32>({20, 30}); 3118928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower op.input_tensors.at(1) = &size_tensor; 3128928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower INFER_OK(op, "[1,?,3,?];[2];[];[]", "[d0_0,20,30,d0_3];[];[]"); 3138928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower} 3148928074ee22d49f4653f0b42993b969f83841b7aA. Unique TensorFlower 315d7e7b7c1dd9af1566945cf5ca78e80b40913a27bA. Unique TensorFlower} // end namespace tensorflow 316