[英]ValueError: Shape must be rank 1 but is rank 0 for 'ROIAlign/Crop' (op: 'CropAndResize') with input shapes: [2,360,475,3], [1,4], [], [2]
I tried to give all input in this function but it comes out problem like below , i not sure what is the empty [] is . 我试图在这个函数中给出所有输入,但它出现了如下的问题,我不确定什么是空[]是。 There are 2 image image in RGB and the original code is from https://github.com/CharlesShang/FastMaskRCNN/blob/master/libs/layers/crop.py . RGB中有2个图像,原始代码来自https://github.com/CharlesShang/FastMaskRCNN/blob/master/libs/layers/crop.py 。
Traceback (most recent call last):
File "croptest.py", line 77, in <module>
crop(img, boxes, batch_inds,1,7,7,'ROIAlign')
File "croptest.py", line 64, in crop
name='Crop')
File "/home/ubuntu/Desktop/WK/my_project/lib/python2.7/site-packages/tensorflow/python/ops/gen_image_ops.py", line 166, in crop_and_resize
name=name)
File "/home/ubuntu/Desktop/WK/my_project/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
op_def=op_def)
File "/home/ubuntu/Desktop/WK/my_project/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2632, in create_op
set_shapes_for_outputs(ret)
File "/home/ubuntu/Desktop/WK/my_project/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1911, in set_shapes_for_outputs
shapes = shape_func(op)
File "/home/ubuntu/Desktop/WK/my_project/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1861, in call_with_requiring
return call_cpp_shape_fn(op, require_shape_fn=True)
File "/home/ubuntu/Desktop/WK/my_project/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 595, in call_cpp_shape_fn
require_shape_fn)
File "/home/ubuntu/Desktop/WK/my_project/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 659, in _call_cpp_shape_fn_impl
raise ValueError(err.message)
ValueError: Shape must be rank 1 but is rank 0 for 'ROIAlign/Crop' (op: 'CropAndResize') with input shapes: [2,360,475,3], [1,4], [], [2].
the code i run is shown as below. 我运行的代码如下所示。
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import glob
import tensorflow as tf
import numpy as np
import cv2
def crop(images, boxes, batch_inds, stride, pooled_height, pooled_width, scope):
"""Cropping areas of features into fixed size
Params:
--------
images: a 4-d Tensor of shape (N, H, W, C)
boxes: rois in the original image, of shape (N, ..., 4), [x1, y1, x2, y2]
batch_inds:
Returns:
--------
A Tensor of shape (N, pooled_height, pooled_width, C)
"""
with tf.name_scope(scope):
boxes = [x / (stride+0.0) for x in boxes]
boxes = tf.reshape(boxes, [-1, 4])
print(images)
print(images.shape)
shape = tf.shape(images)
boxes = tf.reshape(boxes, [-1, 2]) # to (x, y)
xs = boxes[:, 0]
ys = boxes[:, 1]
xs = xs / tf.cast(shape[2], tf.float32)
ys = ys / tf.cast(shape[1], tf.float32)
boxes = tf.concat([ys[:, tf.newaxis], xs[:, tf.newaxis]], axis=1)
boxes = tf.reshape(boxes, [-1, 4]) # to (y1, x1, y2, x2)
assert_op = tf.Assert(tf.greater(tf.size(images), 0), [images, batch_inds])
print(assert_op)
print("-----------------------")
print(images.astype('float'))
print("-----------------------")
print(batch_inds)
x=images.astype('float')
print("-----------------------")
print(batch_inds)
print("-----------------------")
print(pooled_height)
print("-----------------------")
pools =[pooled_height, pooled_width]
arg = tf.convert_to_tensor(x, dtype=tf.float32)
arg1 = tf.convert_to_tensor(batch_inds)
with tf.control_dependencies([assert_op, arg,arg1 ]):
return tf.image.crop_and_resize(images, boxes, batch_inds,
pools,
method='bilinear',
name='Crop')
images = [cv2.imread(file) for file in glob.glob("/home/ubuntu/Pictures/TeImage/*.png")]
img= np.asarray(images)
boxes = [100, 100, 200, 200]
batch_inds=2
crop(img, boxes, batch_inds,1,7,7,'ROIAlign')
[]
means that it was a scalar (aka tensor with rank=0
), and the op is expecting a 1D tensor ( rank=1
). []
表示它是一个标量(也就是具有rank=0
张量),并且op期望一维张量( rank=1
)。 Try to pass something like [batch_inds]
to the crop_and_resize
op, or change it in some other way to make it a vector, not a scalar. 尝试将[batch_inds]
类的内容传递给crop_and_resize
操作crop_and_resize
,或者以其他方式更改它以使其成为向量,而不是标量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.