title: Multiprocessing ResNet Feature Extraction with Image URLs
body: <p>I have a simple function to take an image url and extract features from it using resnet in Keras then hand it off to an Xgboost model loaded from a pkl file. </p>
  
  <pre class="lang-py prettyprint-override"><code>def classify(img, resnet_model, loaded_model):
    try:
      images = io.imread(img.strip())
      images = Image.fromarray(images)
      test_image = img.resize((224,224))
      test_image = image.img_to_array(test_image)
      test_image = expand_dims(test_image, axis = 0)
      img_data = preprocess_input(test_image)
      image_features = resnet_model.predict(img_data)
      image_features_array = array(image_features)
      predicted_image = loaded_model.predict(xgb.DMatrix(DataFrame(image_features_array))) 
    except:
      predicted_image = 'Broken URL'
  
    return predicted_image`
  </code></pre>
  
  <p>Currently I am just looping through a list of img urls and it works fine but I will need it to perform much faster.  The code itself may not be the most efficient yet but I am mostly concerned with multiprocessing.  My attempts either hang or immediately result in an empty list.</p>
  
  <p>There is a similar question posted years ago here: <a href="https://stackoverflow.com/questions/45909738/tensorflow-multiprocessing-for-image-feature-extraction">question</a> but the answers were not very satisfying and involved holding a batch of image files locally. I would prefer to just have one worker making the request for the image and then predicting that image.</p>