Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading a fine-tuned model and getting labels. #11599

Closed
ShiroDXD opened this issue Nov 7, 2018 · 5 comments
Closed

Loading a fine-tuned model and getting labels. #11599

ShiroDXD opened this issue Nov 7, 2018 · 5 comments
Assignees
Labels
stat:awaiting response from contributor type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.

Comments

@ShiroDXD
Copy link

ShiroDXD commented Nov 7, 2018

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

print("[INFO] loading network...")
self.model = load_model(PiVision.h5)

while (~(frame is None)):
    (inID, label) = self.predict(frame)

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)

image = preprocess_input(image)
preds = self.model.predict(image)
return decode_predictions(preds)[0]

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()`

@gabrieldemarmiesse gabrieldemarmiesse added type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited. type: TensorFlow labels Nov 7, 2018
@Harshini-Gadige
Copy link

@ShiroDXD - Hi, does this problem exist when tf.keras is used ?

@ShiroDXD
Copy link
Author

@Harshini-Gadige I haven't tried it on tf.keras though but can you refer me to any blogs or website that has successfully applied a fine-tuned model. Thanks.

@Harshini-Gadige
Copy link

Harshini-Gadige commented Nov 13, 2018

@ShiroDXD - Sure. Please take a look into the below links which help you to fine-tune a model.

Fine-tuning a Keras model
Fine-tuning Mobilenet

@Harshini-Gadige
Copy link

@ShiroDXD Any update on this please ?

@Harshini-Gadige
Copy link

Closing this as it is in "awaiting response" status for more than a week. Feel free to repost your comments and we will reopen. Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting response from contributor type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.
Projects
None yet
Development

No branches or pull requests

3 participants