matatusko / Real-Time-Object-Recognition-in-Keras

Real time object recognition in Keras based on ImageRes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Training data is not recognized

ldg0315 opened this issue · comments

Thank you!
Your project is getting a lot of help with my project. But I have a problem.
I am working on a project using raspberry pi.
I used keras-retinanet to create trained data. I also confirmed that I used test.py to verify that my trained data was successful. And I made some code modifications to use it instead of the VGG. The webcam also worked and there were no error messages at all. But my raspberry pi could not recognize the trained data.

Can you check if there is a problem with my code?
#who.h5 is the file I trained

import tensorflow as tf
from keras.applications import imagenet_utils
from keras_retinanet.models import load_model
from keras.applications import ResNet50
import cv2, threading
import numpy as np

frame_to_predict = None
classification = True
label = ''
score = .0

print('Loading network...')

model = VGG16(weights='imagenet')

model = load_model('/home/pi/Real-Time-Object-Recognition-in-Keras/who.h5', backbone_name='resnet50')

##This is the part I used to apply my training model.
##https://github.com/fizyr/keras-retinanet

graph = tf.get_default_graph()
print('Network loaded successfully!')

class MyThread(threading.Thread):
def init(self):
threading.Thread.init(self)

def run(self):
    global label
    global frame_to_predict
    global classification
    global model
    global graph
    global score

    with graph.as_default():

        while classification is True:
            if frame_to_predict is not None:
                frame_to_predict = cv2.cvtColor(frame_to_predict, cv2.COLOR$
                frame_to_predict = frame_to_predict.reshape((1, ) + frame_t$
                frame_to_predict = imagenet_utils.preprocess_input(frame_to$
                predictions = model.predict(frame_to_predict)
                (imageID, label, score) = imagenet_utils.decode_predictions$

Start a keras thread which will classify the frame returned by openCV

keras_thread = MyThread()
keras_thread.start()

Initialize OpenCV video captue

video_capture = cv2.VideoCapture(0) # Set to 1 for front camera
video_capture.set(4, 800) # Width
video_capture.set(5, 600) # Height

Start the video capture loop

while (True):

Start the video capture loop
while (True):

# Get the original frame from video capture
ret, original_frame = video_capture.read()

# Resize the frame to fit the imageNet default input size
frame_to_predict = cv2.resize(original_frame, (224, 224))

# Add text label and network score to the video captue
cv2.putText(original_frame, "Label: %s | Score: %.2f" % (label, score),
            (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
# Display the video
cv2.imshow("Classification", original_frame)

# Hit q or esc key to exit
if (cv2.waitKey(1) & 0xFF == ord('q')):
    break;

classification = False
video_capture.release()
cv2.destroyAllWindows()