В приведенном ниже примере кода и OUTPUT я получаю сообщение об ошибке " Тензор не может быть отменен, если включено равенство Тензор. Вместо этого используйте тензор.experimental_ref () в качестве ключа. "
Произошла ошибка во время out_boxes, out_scores, out_classes = self.sess.run()
части кода в методе detect_image()
.
Есть ли способ удалить компонент-заполнитель или решить проблему любым другим способом? Я пытался использовать experimental_ref()
в методе detect_image()
, но это не сработало. Не уверен, что мне пришлось что-то делать внутри метода generate()
и при создании заполнителя.
Я также вынужден изменить версии пакета (keras
, tensorflow
), чтобы исправить проблему.
from keras.models import load_model
import tensorflow.compat.v1.keras.backend as K
from yolo3.model import yolo_eval
def generate(self):
model_path = os.path.expanduser(self.model_path)
assert model_path.endswith('.h5'), 'Keras model must be a .h5 file.'
print("This is the model path:\n", model_path)
self.yolo_model = load_model(model_path, compile=False)
print('{} model, anchors, and classes loaded.'.format(model_path))
# Generate colors for drawing bounding boxes.
hsv_tuples = [(x / len(self.class_names), 1., 1.)
for x in range(len(self.class_names))]
self.colors = list(map(lambda x: colorsys.hsv_to_rgb(*x), hsv_tuples))
self.colors = list(
map(lambda x: (int(x[0] * 255), int(x[1] * 255), int(x[2] * 255)),
self.colors))
random.seed(10101) # Fixed seed for consistent colors across runs.
random.shuffle(self.colors) # Shuffle colors to decorrelate adjacent classes.
random.seed(None) # Reset seed to default.
# Generate output tensor targets for filtered bounding boxes.
self.input_image_shape = K.placeholder(shape=(2, ))
boxes, scores, classes = yolo_eval(self.yolo_model.output, self.anchors,
len(self.class_names), self.input_image_shape,
score_threshold=self.score, iou_threshold=self.iou)
xx_placeholders = [ op for op in self.sess.graph.get_operations() if op.type == "Placeholder"]
print("Inside Generate:", xx_placeholders)
print("Inside Generate:", boxes)
print("Inside Generate:", scores)
print("Inside Generate:", classes)
return boxes, scores, classes
def detect_image(self, image):
if self.is_fixed_size:
assert self.model_image_size[0]%32 == 0, 'Multiples of 32 required'
assert self.model_image_size[1]%32 == 0, 'Multiples of 32 required'
boxed_image = letterbox_image(image, tuple(reversed(self.model_image_size)))
else:
new_image_size = (image.width - (image.width % 32),
image.height - (image.height % 32))
boxed_image = letterbox_image(image, new_image_size)
image_data = np.array(boxed_image, dtype='float32')
print(image_data.shape)
image_data /= 255.
image_data = np.expand_dims(image_data, 0) # Add batch dimension.
print('A2')
# XX: Checkpoint
xx_placeholders = [ op for op in self.sess.graph.get_operations() if op.type == "Placeholder"]
print("First:", xx_placeholders)
print("boxes:", self.boxes)
print("scores:", self.scores)
print("classes:", self.classes)
# self.yolo_model.input = image_data
# self.input_image_shape = [image.size[1], image.size[0]]
# K.set_learning_phase(0)
# out_boxes = self.boxes(self.yolo_model.input, slef.input_image_shape, K.learning_phase())
# print("New OutBoxes :", out_boxes)
out_boxes, out_scores, out_classes = self.sess.run(
[self.boxes, self.scores, self.classes],
feed_dict={
self.yolo_model.input: image_data,
self.input_image_shape: [image.size[1], image.size[0]],
K.learning_phase(): 0
})
...
OUTPUT:
This is the model path:
C:/Program Files/Python35/Lib/site-packages/deep_sort_yolov3/model_data/yolo.h5
C:/Program Files/Python35/Lib/site-packages/deep_sort_yolov3/model_data/yolo.h5 model, anchors, and classes loaded.
Inside Generate: [< tf.Operation 'net/images' type=Placeholder >]
Inside Generate: Tensor("concat_11:0", shape=(None, 4), dtype=float32)
Inside Generate: Tensor("concat_12:0", shape=(None,), dtype=float32)
Inside Generate: Tensor("concat_13:0", shape=(None,), dtype=int32)
(416, 416, 3)
A2
First: [< tf.Operation 'net/images' type=Placeholder >]
boxes: Tensor("concat_11:0", shape=(None, 4), dtype=float32)
scores: Tensor("concat_12:0", shape=(None,), dtype=float32)
classes: Tensor("concat_13:0", shape=(None,), dtype=int32)