train an image classification model on Google Traininable Machine: https://teachablemachine.withgoogle.com/ - the first class should be trained on images of the environment with no pet there, the other classes should be trained on images of a respective pet
export the saved model from that website (using their export button). You will want the TFlit format, unquantized. The files will be named: labels.txt and model_unquant.tflite
from tmlib import *
import cv2
import numpy as np
# Load the model - one time only during startup
tm = TeachableMachineTf()
tm.load('/home/pi/teachablemachine-python/tflite_model/model_unquant.tflite', '/home/pi/teachablemachine-python/tflite_model/labels.txt')
# Each time you want to capture an image -
# Turn on camera
cap = cv2.VideoCapture(0)
# Get image
_, img = cap.read()
# Pass image to model, get ID of most likely person
res, name = tm.predict(img)
idx = np.argmax(res)
print(name)
print(res)
print(idx)
My recommendation for pet recognition is:
Training:
labels.txt
andmodel_unquant.tflite
Making a prediction: