2017-12-07 25 views
1

I 이 함수에서 모든 입력을하려고했지만 아래처럼 문제가 발생합니다. 무엇이 빈 []인지 확실하지 않습니다. RGB에는 2 개의 이미지 이미지가 있고 원래 코드는 https://github.com/CharlesShang/FastMaskRCNN/blob/master/libs/layers/crop.py입니다.ValueError : 입력 모양이 [ROIAlign/Crop] (op : 'CropAndResize') 인 경우 형상이 랭크 1이어야하지만 랭크 0이어야합니다. [2,360,475,3], [1,4], [], [2]

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]. 

코드 i는 아래와 같이 표시됩니다.

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') 

답변

0

[]는 스칼라 (rank=0 일명 텐서)는 것을 의미하며, 연산은 1D 텐서 (rank=1)를 기대한다. [batch_inds] 같은 것을 crop_and_resize op에 전달하거나 다른 방법으로 변경하여 스칼라가 아닌 벡터로 만듭니다.

+0

예, 저에게 적합합니다. 고맙습니다 –