How to save openCV as a pickle file?
I have a requirement where I have to deploy this model on Azure container registry and publish it as a Web Service. In order to do that, I need to save the OpenCV model as a pickle file so I can register the model on Azure.
Here is my code to detect faces:
import numpy as np
import cv2
import matplotlib.pyplot as plt
%matplotlib inline
# load the cascade
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
image = cv2.imread('cricketteam.jpg')
# Load the image
plt.figure(figsize=(12,8))
plt.imshow(image, cmap='gray')
plt.show()
# Convert into grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.3,
minNeighbors=3,
minSize=(30, 30)
)
print("Found {0} Faces!".format(len(faces)))
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
status = cv2.imwrite('faces_detected.jpg', image)
print ("Image faces_detected.jpg written to filesystem: ",status)
facesdetected = cv2.imread('faces_detected.jpg')
# Load the image
plt.figure(figsize=(12,8))
plt.imshow(image, cmap='gray')
plt.show()
you need explain this. why a pickle file, exactly ? (it's impossible)
Thanks for the reply. I'm trying to deploy the OpenCV model (detects face) to Azure. During this process, I will have to register the model using the below Python code.
What would I give for the model_path. I usually give the pickle file name in the model path. What should I be giving for the OpenCV model?
what would an "opencv model" be ?
please understand, that opencv is mainly a c++ library, and that the python api are just shallow wrappers around it.
please explain the need for "pickling". again, i doubt, that it is nessecary, and again, you can only pickle pure python state (not c++ pointers)
then, the code above does not make any sense on a webserver (using matplotlib for visualization) -- it's somehow quite obvious, that you did not think this project through to the end.
Okay got it. I don't need to pickle the model. But is it possible to deploy the OpenCV model to Azure?
I'm basically trying to Dockerise a Python application, which is an OpenCV module.
I'm trying to register the model in Azure Machine Learning workspace using the SDK below.
My question is how can I register the OpenCV model if it cannot be pickled since I need to mention the pkl file in the model_path parameter.
Or how do I save and load a OpenCV model?
Is there any other way to deploy OpenCV model on Azure.
Thank you.