PLearn 0.1
|
Tests MaxSubsampling2DModule. More...
#include <MaxSubsamplingTest.h>
Public Member Functions | |
MaxSubsamplingTest () | |
Default constructor. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual MaxSubsamplingTest * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
virtual void | perform () |
The method performing the test. | |
Static Public Member Functions | |
static string | _classname_ () |
static OptionList & | _getOptionList_ () |
static RemoteMethodMap & | _getRemoteMethodMap_ () |
static Object * | _new_instance_for_typemap_ () |
static bool | _isa_ (const Object *o) |
static void | _static_initialize_ () |
static const PPath & | declaringFile () |
Public Attributes | |
int | batch_size |
int | n_input_images |
int | input_images_length |
int | input_images_width |
int | kernel_length |
int | kernel_width |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Protected Attributes | |
int | output_images_length |
int | output_images_width |
int | input_images_size |
int | output_images_size |
int | input_size |
int | output_size |
PP< MaxSubsampling2DModule > | max_module |
PP< PRandom > | random_gen |
Private Types | |
typedef PTest | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Tests MaxSubsampling2DModule.
Definition at line 52 of file MaxSubsamplingTest.h.
typedef PTest PLearn::MaxSubsamplingTest::inherited [private] |
Reimplemented from PLearn::PTest.
Definition at line 54 of file MaxSubsamplingTest.h.
PLearn::MaxSubsamplingTest::MaxSubsamplingTest | ( | ) |
string PLearn::MaxSubsamplingTest::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::PTest.
Definition at line 49 of file MaxSubsamplingTest.cc.
OptionList & PLearn::MaxSubsamplingTest::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::PTest.
Definition at line 49 of file MaxSubsamplingTest.cc.
RemoteMethodMap & PLearn::MaxSubsamplingTest::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::PTest.
Definition at line 49 of file MaxSubsamplingTest.cc.
Reimplemented from PLearn::PTest.
Definition at line 49 of file MaxSubsamplingTest.cc.
Object * PLearn::MaxSubsamplingTest::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::PTest.
Definition at line 49 of file MaxSubsamplingTest.cc.
StaticInitializer MaxSubsamplingTest::_static_initializer_ & PLearn::MaxSubsamplingTest::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::PTest.
Definition at line 49 of file MaxSubsamplingTest.cc.
void PLearn::MaxSubsamplingTest::build | ( | ) | [virtual] |
Post-constructor.
The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.
Reimplemented from PLearn::PTest.
Definition at line 61 of file MaxSubsamplingTest.cc.
{ inherited::build(); build_(); }
void PLearn::MaxSubsamplingTest::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::PTest.
Definition at line 155 of file MaxSubsamplingTest.cc.
References PLCHECK.
{ PLCHECK( input_images_length % kernel_length == 0 ); PLCHECK( input_images_width % kernel_width == 0 ); output_images_length = input_images_length / kernel_length; output_images_width = input_images_width / kernel_width; input_images_size = input_images_length * input_images_width; output_images_size = output_images_length * output_images_width; input_size = n_input_images * input_images_size; output_size = n_input_images * output_images_size; if( !max_module ) { max_module = new MaxSubsampling2DModule(); max_module->n_input_images = n_input_images; max_module->input_images_length = input_images_length; max_module->input_images_width = input_images_width; max_module->kernel_length = kernel_length; max_module->kernel_width = kernel_width; max_module->build(); } if (!random_gen) random_gen = new PRandom(); random_gen->manual_seed(42); }
string PLearn::MaxSubsamplingTest::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::PTest.
Definition at line 49 of file MaxSubsamplingTest.cc.
void PLearn::MaxSubsamplingTest::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::PTest.
Definition at line 81 of file MaxSubsamplingTest.cc.
References batch_size, PLearn::OptionBase::buildoption, PLearn::declareOption(), input_images_length, input_images_size, input_images_width, input_size, kernel_length, kernel_width, PLearn::OptionBase::learntoption, max_module, n_input_images, output_images_length, output_images_size, output_images_width, and output_size.
{ declareOption(ol, "batch_size", &MaxSubsamplingTest::batch_size, OptionBase::buildoption, "Size of batch"); declareOption(ol, "n_input_images", &MaxSubsamplingTest::n_input_images, OptionBase::buildoption, "Number of images in each input vector"); declareOption(ol, "input_images_length", &MaxSubsamplingTest::input_images_length, OptionBase::buildoption, "Length of input images"); declareOption(ol, "input_images_width", &MaxSubsamplingTest::input_images_width, OptionBase::buildoption, "Width of input images"); declareOption(ol, "kernel_length", &MaxSubsamplingTest::kernel_length, OptionBase::buildoption, "Length of the subsampling zone"); declareOption(ol, "kernel_width", &MaxSubsamplingTest::kernel_width, OptionBase::buildoption, "Width of the subsampling zone"); declareOption(ol, "output_images_length", &MaxSubsamplingTest::output_images_length, OptionBase::learntoption, "Length of output images"); declareOption(ol, "output_images_width", &MaxSubsamplingTest::output_images_width, OptionBase::learntoption, "Width of output images"); declareOption(ol, "input_images_size", &MaxSubsamplingTest::input_images_size, OptionBase::learntoption, "input_images_length*input_images_width"); declareOption(ol, "output_images_size", &MaxSubsamplingTest::output_images_size, OptionBase::learntoption, "output_images_length*output_images_width"); declareOption(ol, "input_size", &MaxSubsamplingTest::input_size, OptionBase::learntoption, "n_input_images*input_images_size"); declareOption(ol, "output_size", &MaxSubsamplingTest::output_size, OptionBase::learntoption, "n_input_images*output_images_size"); declareOption(ol, "max_module", &MaxSubsamplingTest::max_module, OptionBase::learntoption, "The MaxSubsampling2DModule we build and test"); /* declareOption(ol, "", &MaxSubsamplingTest::, OptionBase::buildoption, ""); */ // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::MaxSubsamplingTest::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::PTest.
Definition at line 86 of file MaxSubsamplingTest.h.
:
//##### Protected Options ###############################################
MaxSubsamplingTest * PLearn::MaxSubsamplingTest::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::PTest.
Definition at line 49 of file MaxSubsamplingTest.cc.
OptionList & PLearn::MaxSubsamplingTest::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::PTest.
Definition at line 49 of file MaxSubsamplingTest.cc.
OptionMap & PLearn::MaxSubsamplingTest::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::PTest.
Definition at line 49 of file MaxSubsamplingTest.cc.
RemoteMethodMap & PLearn::MaxSubsamplingTest::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::PTest.
Definition at line 49 of file MaxSubsamplingTest.cc.
void PLearn::MaxSubsamplingTest::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::PTest.
Definition at line 70 of file MaxSubsamplingTest.cc.
References PLearn::deepCopyField().
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(max_module, copies); deepCopyField(random_gen, copies); }
void PLearn::MaxSubsamplingTest::perform | ( | ) | [virtual] |
The method performing the test.
A typical test consists in some output (to pout and / or perr), and updates of this object's options.
Reimplemented from PLearn::PTest.
Definition at line 188 of file MaxSubsamplingTest.cc.
References PLearn::argmax(), PLearn::endl(), i, in, PLearn::pout, and PLearn::TMat< T >::resize().
{ Mat in_(batch_size, input_size); Mat out_(batch_size, output_size); Mat argmax_(batch_size, output_size); TMat<Mat> in(batch_size, n_input_images); TMat<Mat> out(batch_size, n_input_images); TMat<Mat> argmax(batch_size, n_input_images); for( int k=0; k<batch_size; k++ ) for( int i=0; i<n_input_images; i++ ) { in(k,i) = in_(k).subVec(i*input_images_size, input_images_size) .toMat(input_images_length, input_images_width); random_gen->fill_random_uniform(in(k,i), -1, 1); out(k,i) = out_(k) .subVec(i*output_images_size, output_images_size) .toMat(output_images_length, output_images_width); argmax(k,i) = argmax_(k) .subVec( i*output_images_size, output_images_size) .toMat(output_images_length, output_images_width); } TVec<Mat*> ports_values(3); ports_values[0] = &in_; ports_values[1] = &out_; ports_values[2] = &argmax_; out_.resize(0, output_size); argmax_.resize(0, output_size); max_module->fprop(ports_values); Mat out_grad_(batch_size, output_size, 1.); Mat in_grad_(batch_size, input_size); TMat<Mat> in_grad(batch_size, n_input_images); for( int k=0; k<batch_size; k++ ) for( int i=0; i<n_input_images; i++ ) { in_grad(k,i) = in_grad_(k) .subVec(i*input_images_size, input_images_size) .toMat(input_images_length, input_images_width); } TVec<Mat*> ports_grad(3); ports_grad[0] = &in_grad_; ports_grad[1] = &out_grad_; ports_grad[2] = NULL; in_grad_.resize(0, input_size); max_module->bpropAccUpdate( ports_values, ports_grad ); for( int k=0; k<batch_size; k++ ) for( int i=0; i<n_input_images; i++ ) { pout << "in("<<k<<","<<i<<") = " << endl << in(k,i) << endl; pout << "out("<<k<<","<<i<<") = " << endl << out(k,i) << endl; pout << "argmax("<<k<<","<<i<<") = " << endl << argmax(k,i) << endl; pout << "in_grad("<<k<<","<<i<<") = " << endl << in_grad(k,i) << endl; } }
Reimplemented from PLearn::PTest.
Definition at line 86 of file MaxSubsamplingTest.h.
Definition at line 63 of file MaxSubsamplingTest.h.
Referenced by declareOptions().
Definition at line 65 of file MaxSubsamplingTest.h.
Referenced by declareOptions().
int PLearn::MaxSubsamplingTest::input_images_size [protected] |
Definition at line 107 of file MaxSubsamplingTest.h.
Referenced by declareOptions().
Definition at line 66 of file MaxSubsamplingTest.h.
Referenced by declareOptions().
int PLearn::MaxSubsamplingTest::input_size [protected] |
Definition at line 109 of file MaxSubsamplingTest.h.
Referenced by declareOptions().
Definition at line 67 of file MaxSubsamplingTest.h.
Referenced by declareOptions().
Definition at line 68 of file MaxSubsamplingTest.h.
Referenced by declareOptions().
Definition at line 112 of file MaxSubsamplingTest.h.
Referenced by declareOptions().
Definition at line 64 of file MaxSubsamplingTest.h.
Referenced by declareOptions().
int PLearn::MaxSubsamplingTest::output_images_length [protected] |
Definition at line 105 of file MaxSubsamplingTest.h.
Referenced by declareOptions().
int PLearn::MaxSubsamplingTest::output_images_size [protected] |
Definition at line 108 of file MaxSubsamplingTest.h.
Referenced by declareOptions().
int PLearn::MaxSubsamplingTest::output_images_width [protected] |
Definition at line 106 of file MaxSubsamplingTest.h.
Referenced by declareOptions().
int PLearn::MaxSubsamplingTest::output_size [protected] |
Definition at line 110 of file MaxSubsamplingTest.h.
Referenced by declareOptions().
PP<PRandom> PLearn::MaxSubsamplingTest::random_gen [protected] |
Definition at line 113 of file MaxSubsamplingTest.h.