title: UnboundLocalError: local variable 'image' referenced before assignment
body: <p>I'm running this code,</p>
  <pre><code>def extract_features(filename, model):
      try:
          image = Image.open(filename)
  
      except:
          print(&quot;ERROR: Couldn't open image! Make sure the image path and extension is correct&quot;)
          
      image = image.resize((299,299))
      image = np.array(image)
      # for images that has 4 channels, we convert them into 3 channels
      if image.shape[2] == 4: 
          image = image[..., :3]
      image = np.expand_dims(image, axis=0)
      image = image/127.5
      image = image - 1.0
      feature = model.predict(image)
      return feature
  </code></pre>
  <p>It gives me this error:</p>
  <blockquote>
  <p>UnboundLocalError: local variable 'image' referenced before assignment</p>
  </blockquote>
  <p>This line</p>
  <pre><code>print(&quot;ERROR: Couldn't open image! Make sure the image path and extension is correct&quot;)
  </code></pre>
  <p>is printed by the interpreter.</p>
  <p>Can someone explain why this error occurred?</p>