InsightFace_TF icon indicating copy to clipboard operation
InsightFace_TF copied to clipboard

About the parse_function

Open HsuTzuJen opened this issue 7 years ago • 4 comments

Hi, Could you tell me how to modify values in tensor like the way using numpy ? I want to add cutout method in the in the parse_function as the paper"https://arxiv.org/abs/1708.04552"

HsuTzuJen avatar Apr 11 '18 11:04 HsuTzuJen

In tensorflow, element-wise assign value to tensor is not allowed. If you want to do element-wise assign you can reference the arcface_loss or cosineface_losses which contains code for assignment by using a mask.

auroua avatar Apr 12 '18 15:04 auroua

I still do not understand how to do it, So I add cutout function "images_train = cutout(images_train, args.cutout_length)" after "images_train, labels_train = sess.run(next_element)"

paper : https://arxiv.org/abs/1708.04552

def cutout(images,length): w = 112 h = 112 length = length images = images for k in range(len(images)): x1 = np.random.randint(w-length) x2 = x1 + length y1 = np.random.randint(h-length) y2 = y1 + length for i in range(x1,x2): for j in range(y1,y2): images[k][i][j][0] = 0 images[k][i][j][1] = 0 images[k][i][j][2] = 0 return images

HsuTzuJen avatar Apr 13 '18 03:04 HsuTzuJen

images[k][i][j][0] = 0 images[k][i][j][1] = 0 images[k][i][j][2] = 0 This is not allowed in tensorflow.

  1. You should build a mask
  2. Set the element in this mask to 1
  3. Set the value of region which you want to use cutout to 0 in the mask.
  4. Do element-wise multiple between the image and the mask.

auroua avatar Apr 13 '18 04:04 auroua

Thank you for the hint. I am still new to TF. By the way, the data type of images_train is numpy.ndarray, so I can do with it directly. I have tried to use the mask in the pharse_function, but the cutout regions are the same in the same batch. Could you please tell me how to fix this?

I think tf map pharse_function by batch, so each batch is matched one pharse_function operation?

HsuTzuJen avatar Apr 13 '18 05:04 HsuTzuJen