tensorflow / models

Models and examples built with TensorFlow
Other
77.19k stars 45.75k forks source link

error running eager_few_shot_od_training_tflite in google colab #10260

Open harrisdj opened 3 years ago

harrisdj commented 3 years ago

Prerequisites

Please answer the following question for yourself before submitting an issue.

1. The entire URL of the documentation with the issue

https://github.com/tensorflow/models/blob/master/research/object_detection/colab_tutorials/eager_few_shot_od_training_tflite.ipynb

2. Describe the issue

Running the notebook in google colab produces an error when processing the visualization of the test predictions:

/usr/local/lib/python3.7/dist-packages/object_detection/utils/visualization_utils.py in

visualize_boxes_and_labels_on_image_array(image, boxes, classes, scores, category_index, instance_masks, instance_boundaries, keypoints, keypoint_scores, keypoint_edges, track_ids, use_normalized_coordinates, max_boxes_to_draw, min_score_thresh, agnostic_mode, line_thickness, mask_alpha, groundtruth_box_visualization_color, skip_boxes, skip_scores, skip_labels, skip_track_ids) 1187 if max_boxes_to_draw == len(box_to_color_map): 1188 break -> 1189 if scores is None or scores[i] > min_score_thresh: 1190 box = tuple(boxes[i].tolist()) 1191 if instance_masks is not None:

IndexError: invalid index to scalar variable.

This appears to be because the assignment of output tensors is incorrect in the detect function: boxes = interpreter.get_tensor(output_details[0]['index']) classes = interpreter.get_tensor(output_details[1]['index']) scores = interpreter.get_tensor(output_details[2]['index'])

this is the output of interpreter.get_output_details():

[{'dtype': numpy.float32,
  'index': 335,
  'name': 'StatefulPartitionedCall:1',
  'quantization': (0.0, 0),
  'quantization_parameters': {'quantized_dimension': 0,
   'scales': array([], dtype=float32),
   'zero_points': array([], dtype=int32)},
  'shape': array([ 1, 10], dtype=int32),
  'shape_signature': array([ 1, 10], dtype=int32),
  'sparsity_parameters': {}},
 {'dtype': numpy.float32,
  'index': 333,
  'name': 'StatefulPartitionedCall:3',
  'quantization': (0.0, 0),
  'quantization_parameters': {'quantized_dimension': 0,
   'scales': array([], dtype=float32),
   'zero_points': array([], dtype=int32)},
  'shape': array([ 1, 10,  4], dtype=int32),
  'shape_signature': array([ 1, 10,  4], dtype=int32),
  'sparsity_parameters': {}},
 {'dtype': numpy.float32,
  'index': 336,
  'name': 'StatefulPartitionedCall:0',
  'quantization': (0.0, 0),
  'quantization_parameters': {'quantized_dimension': 0,
   'scales': array([], dtype=float32),
   'zero_points': array([], dtype=int32)},
  'shape': array([1], dtype=int32),
  'shape_signature': array([1], dtype=int32),
  'sparsity_parameters': {}},
 {'dtype': numpy.float32,
  'index': 334,
  'name': 'StatefulPartitionedCall:2',
  'quantization': (0.0, 0),
  'quantization_parameters': {'quantized_dimension': 0,
   'scales': array([], dtype=float32),
   'zero_points': array([], dtype=int32)},
  'shape': array([ 1, 10], dtype=int32),
  'shape_signature': array([ 1, 10], dtype=int32),
  'sparsity_parameters': {}}]

re-assigning the output tensors produces the expected result:

boxes = interpreter.get_tensor(output_details[1]['index'])
classes = interpreter.get_tensor(output_details[3]['index'])
scores = interpreter.get_tensor(output_details[0]['index'])

though, I admit, I'm not sure this is the most complete way to solve this issue and whether the order of the output tensors is stable

Cipher-zzz commented 3 years ago

Got a same output_details, this solved my problem. Thank you!

zenetio commented 2 years ago

I got the same issue. Thank you!