ThomasDelteil / VisualSearch_MXNet

Visual Search using Apache MXNet and gluon
234 stars 54 forks source link

Custom Codes in visualsearch.py #14

Open adoshi085 opened 5 years ago

adoshi085 commented 5 years ago

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 -

  1. 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
  2. A url of s3 where the .h5 is located - MODEL_URL = '........amazonaws.com/mod_objdet.h5'

  3. 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.

  1. Is this approach appropriate?
  2. Can you suggest me something else which is better than this approach?