yxu0611 / Tensorflow-implementation-of-LCNN

A Tensorflow implementation of "A Light CNN for Deep Face Representation with Noisy Labels"
78 stars 12 forks source link

Welcome to raise issues and your requests here #3

Open yxu0611 opened 6 years ago

AdhamGouda commented 6 years ago

is there any code to try the implementation to verify either it's an image or not? your help is really appreciated

yxu0611 commented 6 years ago

Hi, I assume that you have several different format files, e.g jpg, png, txt, doc, there may be two possible ways to verify the file is a image format or not. Solution 1:

from os import listdir
import os

img_format = ['.jpg', '.jpeg', '.png', '.tif']
list_img = listdir(path_img_folder)
for img_name in list_img:
     extension = os.path.splitext(img_name)[1]
     if extension in img_format:
         print("It's image")
     else:
        print("It's not image")

Solution 2: You can probably use opencv function. e.g. cv2.imread(img_path), if the output returns NULL, it means your input file is not basically image format

AdhamGouda commented 6 years ago

Sorry I meant a code to verify if this is the person or not to verify the face not to recognize ,any tips ? thank you so much

tensorflowt commented 6 years ago

@AdhamGouda the input_size of model is 1281283,but why you need to resize to 144144?

yxu0611 commented 6 years ago

@tensorflowt It's because we did randomly cropping from 144x144 to 128x128

tensorflowt commented 6 years ago

what half means in the function MFMfc? def MFMfc(x,half,name): with tf.variable_scope(name): shape = x.get_shape().as_list() res = tf.reduce_max(tf.reshape(x,[-1,2,shape[-1]//2]),reduction_indices=[1]) return res

yxu0611 commented 6 years ago

@tensorflowt MFMfc is represented as an active function( similar to maxout), meanwhile, it also can perform feature dimension reduction. See the explanation from paper[1]: wechat screenshot_20180601135131

[1] Wu, Xiang, et al. "A light CNN for deep face representation with noisy labels." arXiv preprint arXiv:1511.02683 (2015).

fraserprice commented 6 years ago

@yxu0611 How is image pre-processing performed? The paper states that images are transformed to greyscale and rotated based upon facial features; there doesn't seem to be any function in the code to perform this.

yxu0611 commented 6 years ago

@fraserprice These pre-processing codes can be found as below. We did the rotation and transformation based on 3 facial points (left eye, right eye, and mouth)

# get grey scale image
img = cv2.imread(img_path, 0)

# get the left/right center eye position 
leye = np.float32([points[0], points[1]])
reye = np.float32([points[2], points[3]])

# get the center mouth position 
lmouth = np.float32([points[6], points[7]])
rmouth = np.float32([points[8], points[9]])
mouth = [(lmouth[0]+rmouth[0])/2., (lmouth[1]+rmouth[1])/2.]

# set eye to eye pixel distance 90, eye to mouth pixel distance 87 (template image size: 256x300) 
src = np.float32([leye, reye, mouth])
dst = np.float32([[88, 125], [178, 125], [133, 212]])
M = cv2.getAffineTransform(src, dst)
crop_image = cv2.warpAffine(img, M, (256, 300))

# resize cropped image from 256x300 to 122x144
crop_image2  = cv2.resize(crop_image , (122, 144))
ehion commented 6 years ago

Don't understand sum function in you code,could you please explain it ,thx

ehion commented 6 years ago
def sum(self, layerin):
        layer1_size = self.res_size
        layer2_size = layerin[1]
        print (layer1_size[2], layer1_size[3])
        print (layer2_size[2], layer2_size[3])
        assert layer1_size[1] == layer2_size[1]
        assert layer1_size[2] == layer2_size[2] and layer1_size[3] == layer2_size[3]

        inp_size = self.res_size
        with tf.name_scope('sum_' + str(self.layer_num)):
            self.res = self.res + layerin[0]
            self.res_size = self.res.get_shape()

        print ('sum_'+str(self.layer_num), inp_size, self.res_size)
        return [self.res, self.res_size]
ehion commented 6 years ago
mod = M.Model(img_holder, [None, 128, 128, 3])

    mod.conv_layer(5, 96, activation=1)
    mod.maxpooling_layer(2, 2) #pool1

    # 
    a = mod.get_current_layer()
    mod.conv_layer(3, 96, activation=1)
    mod.conv_layer(3, 96, activation=1)
    # print (mod.get_shape())

    mod.sum(a)
gdescamps commented 5 years ago

@ehion It seems to be the residual shortcuts, see

shi-xingping commented 5 years ago

hello,I am sorry to disturb you,but I encountered such a problem during training. Limited by my graphics card memory, I changed BAZIE to 200. there were an error on the 1803th iteration of epoch1: indexerror:too many indices for arry When I modified the batchsize to 240, I got another error: index 80 is out of the bounds for axis 0 with size 80. Both error locations are near line 126 of lcnn29.py. I have no idea. Hope to get help. thanks a lot