Question/Issue:
I would like to use the generated model for my raspberry pi to process images coming as post requests to my flask server
Context/Use case:
I have already tested this model on my device and it working as desired it’s just that I want to extend this project a bit and add a flask server that receives images from POST request and then process them using the trained model
from cv2 import imread
from flask import Flask, request
from edge_impulse_linux.image import ImageImpulseRunner
import os
import cv2
model = "modelfile2.eim"
app = Flask(__name__)
@app.route('/get_features', methods=['POST'])
def get_features():
if 'image' not in request.files:
return 'No image provided', 400
dir_path = os.path.dirname(os.path.realpath(__file__))
modelfile = os.path.join(dir_path, model)
with ImageImpulseRunner(modelfile) as runner:
try:
model_info = runner.init()
print('Loaded runner for "' + model_info['project']['owner'] + ' / ' + model_info['project']['name'] + '"')
labels = model_info['model_parameters']['labels']
img = request.files['image'].read()
img = imread(img)
if img is None:
raise Exception('Failed to load image')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
features, cropped = runner.get_features_from_image(img)
return {'features': list(features)}
except Exception as e:
print('Failed to delete %s. Reason: %s' % ("Error :", e))
if __name__ == '__main__':
app.run(debug=True)
This is the code I am currently using but it throws an error saying
AttributeError: 'ImageImpulseRunner' object has no attribute 'get_features'
also :
Exec format error: '/file/test/modelfile2.eim'