title: Tensorflow/Keras with django not working correctly with celery
body: <p>We are building a script for face recognition, mainly with tensorflow for basic recognition functions, from videos.</p>
  
  <p>When we try the soft directly with a <code>python test-reco.py</code> (which take a video path as parameter) it works perfectly.</p>
  
  <p>Now we are trying to integrate it through our website, within a celery task.</p>
  
  <p>Here is the main code:</p>
  
  <pre><code>def extract_labels(self, path_to_video):
      if not os.path.exists(path_to_video):
          print("NO VIDEO!")
          return None
      video = VideoFileClip(path_to_video)
      n_frames = int(video.fps * video.duration)
  
      out = []
      for i, frame in enumerate(video.iter_frames()):
          if self.verbose &gt; 0:
              print(
                  'processing frame:',
                  str(i).zfill(len(str(n_frames))),
                  '/',
                  n_frames
              )
  
          try:
              rect = face_detector(frame[::2, ::2], 0)[0]
              y0, x0, y1, x1 = np.array([rect.left(), rect.top(), rect.right(), rect.bottom()])*2
              bbox = frame[x0:x1, y0:y1]
              bbox = resize(bbox, [128, 128])
              bbox = rgb2gray(bbox)
              bbox = equalize_hist(bbox)
              y_hat = self.model.predict(bbox[None, :, :, None], verbose=1, batch_size=1)[0]
              # y_hat = np.ones(7)
              out.append(y_hat)
          except IndexError as e:
              print(out)
              print(e)
  </code></pre>
  
  <p>We need a try catch because sometimes there aren't any face present in the first frames.</p>
  
  <p>But then we have this line:
  <code>y_hat = self.model.predict(bbox[None, :, :, None], verbose=1, batch_size=1)[0]</code>
  blocking. Like an endless loop.</p>
  
  <p>The bbox isn't empty.</p>
  
  <p>The celery worker simply blocks on it and you can't exit the process (the warm / cold quit never occurs)</p>
  
  <p>Is there something specific to do with tensorflow with Celery?</p>