title: remove background using u2net produced mask
body: <p>I am trying to remove background from an image. For this purpose I am using <a href="https://arxiv.org/pdf/2005.09007v3.pdf" rel="nofollow noreferrer">U2NET</a>. I am writing the network structure using Tensorflow by following this <a href="https://github.com/Akhilesh64/Image-Segmentation-U-2-Net" rel="nofollow noreferrer">repository</a>. I have changed the model architecture according to my needs. It takes 96x96 image and produces 7 masks. I am taking 1st mask (out of 7) and multiplying it against the all channels of original 96x96 image.</p>
  <p>The code that predicts 7 masks is:</p>
  <pre><code>img = Image.open(os.path.join('DUTS-TE','DUTS-TE-Image', test_x_names[90]))
  copied = deepcopy(img)
  copied = copied.resize((96,96))
  copied = np.expand_dims(copied,axis=0)
  preds = model.predict(copied)
  preds = np.squeeze(preds)
  </code></pre>
  <p>&quot;preds[0]&quot; is:</p>
  <p><a href="https://i.stack.imgur.com/nK0ov.png" rel="nofollow noreferrer">predicted mask</a></p>
  <p>Multiplying the mask against the original image produces:
  <a href="https://i.stack.imgur.com/EM9Eb.png" rel="nofollow noreferrer">masked image</a>  and corresponding code is (&quot;img2&quot; is original image):</p>
  <pre><code>img2 = np.asarray(img2)
  immg = np.zeros((96,96,3), np.uint8)
  for i in range(0,3):
    immg[:,:,i] = img2[:,:,i] * preds[0]
  plt.imshow(immg)
  plt.show()
  </code></pre>
  <p>If i binarize the mask and then multiply it against the original image it produces :
  <a href="https://i.stack.imgur.com/24rQb.png" rel="nofollow noreferrer">enter image description here</a> and corresponding code is :</p>
  <pre><code>frame = binarize(preds[0,:,:], threshold = 0.5)
  img2 = np.asarray(img2)
  immg = np.zeros((96,96,3), np.uint8)
  for i in range(0,3):
    immg[:,:,i] = img2[:,:,i] * frame
  plt.imshow(immg)
  plt.show()
  </code></pre>
  <p>Multiplying the original image with mask or binarized mask do not segment the foreground properly from the background. So, what can be done? Am I missing something?</p>