fizyr / keras-retinanet

Keras implementation of RetinaNet object detection.
Apache License 2.0
4.37k stars 1.97k forks source link

ValueError: Dimension 0 in both shapes must be equal, but are 3 and 243. Shapes are [3,3,256,720] and [243,256,3,3]. for 'Assign_299' (op: 'Assign') with input shapes: [3,3,256,720], [243,256,3,3]. #759

Closed MuhammadHuss closed 5 years ago

MuhammadHuss commented 5 years ago

i am stuck while r&d on this issue please help me out.TIA

hgaiser commented 5 years ago

What command are you running?

What keras-retinanet version are you running?

What keras version are you runnig?

What tensorflow version are you running?

Did you make any modifications?

What generator are you using?

What backend are you using?

A little more information would really help solve your problem a lot quicker.

MuhammadHuss commented 5 years ago

for training python train.py csv annonation.csv labels.csv keras_resnet=0.1.0 keras=2.2.4 tensorflow=1.5.0 i did not modify any changing in train.py what mean by generator and backend the model was successfully created but when use this to detect object it give this error following code i m using for detection from imageai.Detection import ObjectDetection import os from time import time

execution_path = os.getcwd()

detector = ObjectDetection() detector.setModelTypeAsRetinaNet() detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best.h5")) detector.loadModel()

our_time = time() custom_objects = detector.CustomObjects(car=True, motorcycle=True) detections = detector.detectCustomObjectsFromImage(custom_objects=custom_objects, input_image=os.path.join(execution_path , "1539341094185.jpg"), output_image_path=os.path.join(execution_path , "image3custom.jpg")) print("IT TOOK : ", time() - our_time) for eachObject in detections: print(eachObject["name"] + " : " + eachObject["percentage_probability"] ) print("--------------------------------")

hgaiser commented 5 years ago

from imageai.Detection import ObjectDetection

This is not a part of keras-retinanet, I think you're asking the question on the wrong repository.

Also, that tensorflow version is quite old, consider updating it to 1.11.

MuhammadHuss commented 5 years ago
import keras

# import keras_retinanet
from keras_retinanet import models
from keras_retinanet.utils.image import read_image_bgr, preprocess_image, resize_image
from keras_retinanet.utils.visualization import draw_box, draw_caption
from keras_retinanet.utils.colors import label_color

# import miscellaneous modules
import matplotlib.pyplot as plt
import cv2
import os
import numpy as np
import time

# set tf backend to allow memory to grow, instead of claiming everything
import tensorflow as tf

def get_session():
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    return tf.Session(config=config)

# use this environment flag to change which GPU to use
#os.environ["CUDA_VISIBLE_DEVICES"] = "1"

# set the modified tf session as backend in keras
keras.backend.tensorflow_backend.set_session(get_session())

model_path = 'resnet50_01_coco.h5'

# load retinanet model
model = models.load_model(model_path, backbone_name='resnet50')

# if the model is not converted to an inference model, use the line below
# see: https://github.com/fizyr/keras-retinanet#converting-a-training-model-to-inference-model
#model = models.convert_model(model)

#print(model.summary())

# load label to names mapping for visualization purposes
labels_to_names = {0: 'Lays_Yougart_50', 1: 'Lays_Yougart_30', 2: 'Lays_Yougart_20'}
# load image
image = read_image_bgr('20181012_145812.jpg')

# copy to draw on
draw = image.copy()
draw = cv2.cvtColor(draw, cv2.COLOR_BGR2RGB)

# preprocess image for network
image = preprocess_image(image)
image, scale = resize_image(image)

# process image
start = time.time()
boxes, scores, labels = model.predict_on_batch(np.expand_dims(image, axis=0))
print("processing time: ", time.time() - start)

# correct for image scale
boxes /= scale

# visualize detections
for box, score, label in zip(boxes[0], scores[0], labels[0]):
    # scores are sorted so we can break
    if score < 0.5:
        break

    color = label_color(label)

    b = box.astype(int)
    draw_box(draw, b, color=color)

    caption = "{} {:.3f}".format(labels_to_names[label], score)
    draw_caption(draw, b, caption)

plt.figure(figsize=(15, 15))
plt.axis('off')
plt.imshow(draw)
plt.show()