2017-11-14 5 views
2

tensorflow detection tutorial, 을 사용하여 일괄 처리 검색을 수행하려고하지만 다음 코드는 setting an array element with a sequence. 오류를 표시합니다.Tensorflow 개체 검색 : 일괄 검색 방법

# load multiple images 
np_images = [] 
for img_path in img_paths: 
    img = Image.open(image_path) 
    image_np = load_image_into_numpy_array(img)  
    image_np_expanded = np.expand_dims(image_np, axis=0) 
    np_images.append(image_np) 

#Get input and output tensors 
image_tensor = det_graph.get_tensor_by_name('image_tensor:0') 
boxes = det_graph.get_tensor_by_name('detection_boxes:0')  
scores = det_graph.get_tensor_by_name('detection_scores:0') 
classes = det_graph.get_tensor_by_name('detection_classes:0') 
num_detections = det_graph.get_tensor_by_name('num_detections:0') 

# detect on batch of images 
detection_results = sess.run(
     [boxes, scores, classes, num_detections], 
     feed_dict={image_tensor: np_images}) 

이미지 배열을 올바르게 공급하는 방법은 무엇입니까?

+0

스택 추적과 함께 오류 메시지를 제공 할 수 있습니까? –

답변

1

feed_dict의 image_tensor 크기는 [batch_size, x, y, 3]이어야합니다. 여기서 (x, y)는 각 이미지의 크기입니다. 이미지 크기가 모두 다르다면 그런 수위가 낮은 배열을 만들 수 없습니다. 이 문제를 해결하기 위해 이미지의 크기를 조정할 수 있습니다.

# If the NN was trained on (300,300) size images 
IMAGE_SIZE = (300, 300) 
for img_path in img_paths: 
    img = Image.open(image_path).resize(IMAGE_SIZE) 
    image_np = load_image_into_numpy_array(img)  
    np_images.append(image_np) 
... 
detection_results = sess.run(
    [boxes, scores, classes, num_detections], 
    feed_dict={image_tensor: np.array(np_images)})