mks0601 / A-Convolutional-Neural-Network-Cascade-for-Face-Detection

TensorFlow implementation of "A Convolutional Neural Network Cascade for Face Detection", CVPR 2015
http://www.cv-foundation.org/openaccess/content_cvpr_2015/papers/Li_A_Convolutional_Neural_2015_CVPR_paper.pdf
109 stars 62 forks source link

for cascade_lv in xrange(1,etc.cascade_level) #3

Closed tengshaofeng closed 7 years ago

tengshaofeng commented 7 years ago

dear mks0601: i am so appreciated with your great work. I have read your code these days. The following code comes my question:

code start

for cascade_lv in xrange(1,etc.cascade_level): #question

if cascade_lv > 1:
    print "Training start!"
    train_start = time.time()
    fp_loss = open("./result/loss_" + str(cascade_lv) + "_.txt", "w")

    for e in xrange(etc.epoch_num[cascade_lv]):

        fp_conf_mat = open("./result/conf_mat_" + str(e) + "_.txt","w")  
        epoch_start = time.time()
        average_loss = 0

        for b_iter in xrange(etc.batch_iter):

            pos_id = random.sample(xrange(len(pos_db)),etc.pos_batch)
            neg_id = random.sample(xrange(len(neg_db)),etc.neg_batch)

            if cascade_lv == 0:            #question
                db_12[:etc.pos_batch,:] = pos_db[pos_id,:etc.dim_12]
                db_12[etc.pos_batch:,:] = neg_db[neg_id,:etc.dim_12]
                lb[:etc.pos_batch,:] = np.ones((etc.pos_batch,1),np.float32)
                lb[etc.pos_batch:,:] = np.zeros((etc.neg_batch,1),np.float32)
                zipped = zip(db_12, lb)
                np.random.shuffle(zipped)

code ending

So, "for cascade_lv in xrange(1,etc.cascade_level)", cascade_lv is in [1,2,3].

However "if cascade_lv == 0: ", i want to know xrange or range??? Look forward to your reply

tengshaofeng commented 7 years ago

Another problem, when i run your code with all the input data ready, comes the following error : Traceback (most recent call last): File "train.py", in saver_detect.restore(sess,etc.save_dir+"24-net.ckpt") raise ValueError("Restore called with invalid save path %s" % save_path) ValueError: Restore called with invalid save path

I thought that calling restore function before saver.save? So dose the code is the latest code ?

mks0601 commented 7 years ago

Hi tengshaofeng

First of all, i ran some experiments so that i modified some conditions. For the first issue, in train.py 193 line,

for cascade_lv in xrange(1,etc.cascade_level):

if cascade_lv > 1:

the xrange of cascade_lv should be xrange(0,etc.cascade_level) and the if statement should be removed.

Maybe i trained the model whose cascade_lv is 2(48-net). So, hard neg mining from cascade_lv 1(24-net) and train the 48-net.

Also, for the second issue, you may understand why there is restore function before save. I loaded 24-net and hard neg mining and train 48-net.

tengshaofeng commented 7 years ago

I have understand what you said. Thanks very much. restore error from following code:

code start

if cascade_lv == 0: saver_detect.restore(sess,etc.save_dir+"12-net.ckpt") elif cascade_lv == 1: saver_detect.restore(sess,etc.save_dir+"24-net.ckpt")

saver_calib_12.restore(sess,etc.save_dir+"12-net_calib.ckpt")
saver_calib_24.restore(sess,etc.save_dir+"24-net_calib.ckpt")

code end

So shoud i run train_cali.py first?

mks0601 commented 7 years ago

training order is as follow: (12-net, 12-calib-net), (24-net, 24-calib-net), (48-net, 48-calib-net) the order in parenthesis does not matter

that restore is to collect hard negative from 12-net and 12-calib net

tengshaofeng commented 7 years ago

ok, it is so clear. Thank you very much. Here is the last question. It seems that your "normalization layer" keeps blank. Tensorflow does not have the function to acheive it ? I am the beginner to tensorflow. Sorry to bother you all the time.

mks0601 commented 7 years ago

I do not know whether there is normalization layer or not and that is why i omitted the normalization layer.

tengshaofeng commented 7 years ago

I think there is a normalization layer (LRN).

96imranahmed commented 7 years ago

Hi @tengshaofeng, did you implement the LRN in the end? Did it give you any training speed boosts?

Also can I confirm, to train, do you guys run train.py and then afterwards run train_calib.py? I'm confused as to how you train both the 12-net and 12-calib-net in parallel?

Also, thank you so much for this implementation @mks0601!

mks0601 commented 7 years ago

As I said, 12-net and 12-calib net is different network. You do not need to train these networks simultaneously.

96imranahmed commented 7 years ago

@mks0601 , Right ok - that's what I was thinking (having read through the paper)! So I was just a bit confused!

Thanks for the response!

tengshaofeng commented 7 years ago

Hi,@96imranahmed, for the 1st question, I have implemented the LRN, but I didn't investigate whether it can boost the training speed. I just do it like the paper said.
for the 2nd question, You can train the all the 12-24-48-calib-net first then train the 12-24-48-net. if you have several machines gpu, you can train the 12-net on one machine, and train 24-cali-net on another machine.

ShuoYe2020 commented 6 years ago

Dear @mks0601 @tengshaofeng ,Sorry to bother you again, I'm running 'test.py' now, This should be the last step for the CNN_cascade, however when the code execute at 'load_db_test()', I found all the 'FDDB-fold-0X-ellipseList.txt' is empty, I am confused, could you please tell me when did you write data in this file?