Skip to content

Should we set the phase as TEST when creating the test_net in solver.cpp? #192

@huangjunshi

Description

@huangjunshi

At line 32 of solver.cpp (of master branch), before creating the test_net, I think we should set the phase as TEST (and set back to TRAIN when finish), otherwise it will induce a small bug in the data_layer.cpp if we enable the cropsize parameter at the same time.

Assuming we set the cropsize parameter as positive number. Because the Caffe::TRAIN is the default value of phase_ in class Caffe (line 23, common.cpp), the first batch of testing data will get rand offset (line 53, data_layer.cpp) if we don't set the phase as TEST when creating the test_net.

To double-check, I just add the printing command at line 53 of data_layer.cpp:

... ...
if (Caffe::phase() == Caffe::TRAIN) {
    if (itemid == 0)    LOG(INFO) << "Read training data from: " << layer->db_;
    h_off = rand() % (height - cropsize);
    w_off = rand() % (width - cropsize);
  } else {
... ...

and here is the partial output:

... ...
I0307 19:58:55.497272 36012 solver.cpp:26] Creating training net.
... ...
I0307 19:58:55.752095 36012 net.cpp:70] Creating Layer conv1
I0307 19:58:55.752102 36012 net.cpp:80] conv1 <- data
I0307 19:58:55.752113 36012 net.cpp:105] conv1 -> conv1
I0307 19:58:56.094907 36015 data_layer.cpp:53] Read training data from: 0x1632d60
I0307 19:58:56.094985 36015 data_layer.cpp:53] Read training data from: 0x1632d60
I0307 19:58:56.094985 36015 data_layer.cpp:53] Read training data from: 0x1632d60
I0307 19:58:56.095022 36015 data_layer.cpp:53] Read training data from: 0x1632d60
... ...
I0307 19:58:56.108678 36012 solver.cpp:29] Creating testing net.
... ...
I0307 19:58:56.252768 36012 net.cpp:70] Creating Layer conv1
I0307 19:58:56.252774 36012 net.cpp:80] conv1 <- data
I0307 19:58:56.252782 36012 net.cpp:105] conv1 -> conv1
I0307 19:58:56.252799 36017 data_layer.cpp:53] Read training data from: 0x17452d0
I0307 19:58:56.252854 36017 data_layer.cpp:53] Read training data from: 0x17452d0
... ...

Obviously, the address 0x17452d0 is the address of test_net->db_ (in my case), while the phase is TRAIN.

Pls ignore me if I make any mistake. :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions