mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 06:26:29 +08:00
parent
e8348e5f64
commit
a82c50eac2
@ -42,6 +42,7 @@ public:
|
|||||||
CV_Check(interpolation, interpolation == "nearest" || interpolation == "opencv_linear" || interpolation == "bilinear", "");
|
CV_Check(interpolation, interpolation == "nearest" || interpolation == "opencv_linear" || interpolation == "bilinear", "");
|
||||||
|
|
||||||
alignCorners = params.get<bool>("align_corners", false);
|
alignCorners = params.get<bool>("align_corners", false);
|
||||||
|
halfPixelCenters = params.get<bool>("half_pixel_centers", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
||||||
@ -114,7 +115,7 @@ public:
|
|||||||
|
|
||||||
Mat& inp = inputs[0];
|
Mat& inp = inputs[0];
|
||||||
Mat& out = outputs[0];
|
Mat& out = outputs[0];
|
||||||
if (interpolation == "nearest" || interpolation == "opencv_linear")
|
if (interpolation == "nearest" || interpolation == "opencv_linear" || (interpolation == "bilinear" && halfPixelCenters))
|
||||||
{
|
{
|
||||||
InterpolationFlags mode = interpolation == "nearest" ? INTER_NEAREST : INTER_LINEAR;
|
InterpolationFlags mode = interpolation == "nearest" ? INTER_NEAREST : INTER_LINEAR;
|
||||||
for (size_t n = 0; n < inputs[0].size[0]; ++n)
|
for (size_t n = 0; n < inputs[0].size[0]; ++n)
|
||||||
@ -236,6 +237,7 @@ protected:
|
|||||||
String interpolation;
|
String interpolation;
|
||||||
float scaleWidth, scaleHeight;
|
float scaleWidth, scaleHeight;
|
||||||
bool alignCorners;
|
bool alignCorners;
|
||||||
|
bool halfPixelCenters;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1962,6 +1962,9 @@ void TFImporter::populateNet(Net dstNet)
|
|||||||
if (hasLayerAttr(layer, "align_corners"))
|
if (hasLayerAttr(layer, "align_corners"))
|
||||||
layerParams.set("align_corners", getLayerAttr(layer, "align_corners").b());
|
layerParams.set("align_corners", getLayerAttr(layer, "align_corners").b());
|
||||||
|
|
||||||
|
if (hasLayerAttr(layer, "half_pixel_centers"))
|
||||||
|
layerParams.set("half_pixel_centers", getLayerAttr(layer, "half_pixel_centers").b());
|
||||||
|
|
||||||
int id = dstNet.addLayer(name, "Resize", layerParams);
|
int id = dstNet.addLayer(name, "Resize", layerParams);
|
||||||
layer_id[name] = id;
|
layer_id[name] = id;
|
||||||
|
|
||||||
|
@ -81,12 +81,12 @@ class Test_TensorFlow_layers : public DNNTestLayer
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void runTensorFlowNet(const std::string& prefix, bool hasText = false,
|
void runTensorFlowNet(const std::string& prefix, bool hasText = false,
|
||||||
double l1 = 0.0, double lInf = 0.0, bool memoryLoad = false)
|
double l1 = 0.0, double lInf = 0.0, bool memoryLoad = false, const std::string& groupPrefix = "")
|
||||||
{
|
{
|
||||||
std::string netPath = path(prefix + "_net.pb");
|
std::string netPath = path(prefix + groupPrefix + "_net.pb");
|
||||||
std::string netConfig = (hasText ? path(prefix + "_net.pbtxt") : "");
|
std::string netConfig = (hasText ? path(prefix + groupPrefix + "_net.pbtxt") : "");
|
||||||
std::string inpPath = path(prefix + "_in.npy");
|
std::string inpPath = path(prefix + "_in.npy");
|
||||||
std::string outPath = path(prefix + "_out.npy");
|
std::string outPath = path(prefix + groupPrefix + "_out.npy");
|
||||||
|
|
||||||
cv::Mat input = blobFromNPY(inpPath);
|
cv::Mat input = blobFromNPY(inpPath);
|
||||||
cv::Mat ref = blobFromNPY(outPath);
|
cv::Mat ref = blobFromNPY(outPath);
|
||||||
@ -975,10 +975,53 @@ TEST_P(Test_TensorFlow_layers, keras_mobilenet_head)
|
|||||||
runTensorFlowNet("keras_learning_phase");
|
runTensorFlowNet("keras_learning_phase");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TF case: align_corners=False, half_pixel_centers=False
|
||||||
TEST_P(Test_TensorFlow_layers, resize_bilinear)
|
TEST_P(Test_TensorFlow_layers, resize_bilinear)
|
||||||
{
|
{
|
||||||
runTensorFlowNet("resize_bilinear");
|
runTensorFlowNet("resize_bilinear");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TF case: align_corners=True, half_pixel_centers=False
|
||||||
|
TEST_P(Test_TensorFlow_layers, resize_bilinear_align_corners)
|
||||||
|
{
|
||||||
|
runTensorFlowNet("resize_bilinear",
|
||||||
|
false, 0.0, 0.0, false, // default parameters
|
||||||
|
"_align_corners");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TF case: align_corners=False, half_pixel_centers=True
|
||||||
|
TEST_P(Test_TensorFlow_layers, resize_bilinear_half_pixel)
|
||||||
|
{
|
||||||
|
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
||||||
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||||
|
|
||||||
|
runTensorFlowNet("resize_bilinear", false, 0.0, 0.0, false, "_half_pixel");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TF case: align_corners=False, half_pixel_centers=False
|
||||||
|
TEST_P(Test_TensorFlow_layers, resize_bilinear_factor)
|
||||||
|
{
|
||||||
runTensorFlowNet("resize_bilinear_factor");
|
runTensorFlowNet("resize_bilinear_factor");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TF case: align_corners=False, half_pixel_centers=True
|
||||||
|
TEST_P(Test_TensorFlow_layers, resize_bilinear_factor_half_pixel)
|
||||||
|
{
|
||||||
|
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
||||||
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
||||||
|
|
||||||
|
runTensorFlowNet("resize_bilinear_factor", false, 0.0, 0.0, false, "_half_pixel");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TF case: align_corners=True, half_pixel_centers=False
|
||||||
|
TEST_P(Test_TensorFlow_layers, resize_bilinear_factor_align_corners)
|
||||||
|
{
|
||||||
|
runTensorFlowNet("resize_bilinear_factor", false, 0.0, 0.0, false, "_align_corners");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TF case: align_corners=False, half_pixel_centers=False
|
||||||
|
TEST_P(Test_TensorFlow_layers, resize_bilinear_down)
|
||||||
|
{
|
||||||
runTensorFlowNet("resize_bilinear_down");
|
runTensorFlowNet("resize_bilinear_down");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user