Custom Codes in visualsearch.py
Hi Thomas, Can you tell me how do I put custom codes in visualsearch.py
Let's say that I want to do some Object Detection using some other framework (Keras-retinanet) and then I want to find feature vector for every object detected in the image. I was thinking to add these steps inside the _preprocess function of visualsearch.py
VisualSearch.py would look like -
- Importing additional keras_retinanet libraries
import keras
import tensorflow as tf
from keras_retinanet.models import load_model # Helps in loading object detection model
from keras_retinanet.utils.image import read_image_bgr, preprocess_image, resize_image
-
A url of s3 where the .h5 is located -
MODEL_URL = '........amazonaws.com/mod_objdet.h5' -
class VisualSearchService(MXNetBaseService) will have codes to download the model and load the model
model_url = os.environ.get('MODEL_URL', MODEL_URL)
mx.test_utils.download(model_url, dirname=data_dir)
self.model = load_model(os.path.join(data_dir, 'mod_objdet.h5'), backbone_name='resnet50')
_preprocess function should have the codes that will generate bounding boxes, cropping the image and then finding the feature vector for each cropped item.
I tried it locally by running the mxnet-model-server after archiving all the files but it doesnt seem to work.
Gives me the following error -
' ModuleNotFoundError: No module named 'keras_retinanet'
I m running this inside an env which has Keras-retinanet and mxnet and their dependencies.
- Is this approach appropriate?
- Can you suggest me something else which is better than this approach?