Loading a fine-tuned model and getting labels. #11599
Labels
stat:awaiting response from contributor
type:support
User is asking for help / asking an implementation question. Stackoverflow would be better suited.
I fine tuned Mobilenets and attempted to classify images to a live webcam feed using OpenCV but I cant seem to find a way to get predictions. How can I also get the labels from the retrain process when there is no option in keras to save .pbtxt
I tried loading a fine tuned model saved as a .h5 file to this script but it just kept loading in Jupyter Notebook. What is the correct argument to use so I can deploy the model on a real time camera feed?
Heres my code:
`from keras.preprocessing import image
from keras import load_model
import argparse
import cv2
import numpy as np
import os
import random
import sys
import threading
label = ''
frame = None
class MyThread(threading.Thread):
def init(self):
threading.Thread.init(self)
def run(self):
global label
def predict(self, frame):
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB).astype(np.float32)
image = image.transpose((2, 0, 1))
image = image.reshape((1,) + image.shape)
cap = cv2.VideoCapture(0)
if (cap.isOpened()):
print("Camera OK")
else:
cap.open()
keras_thread = MyThread()
keras_thread.start()
while (True):
ret, original = cap.read()
frame = cv2.resize(original, (224, 224))
Display the predictions
print("ImageNet ID: {}, Label: {}".format(inID, label))
cv2.putText(original, "Label: {}".format(label), (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
cv2.imshow("Classification", original)
if (cv2.waitKey(1) & 0xFF == ord('q')):
break;
cap.release()
frame = None
cv2.destroyAllWindows()
sys.exit()`
The text was updated successfully, but these errors were encountered: