├── LICENSE ├── README.md ├── cache └── README.md ├── caffe-wsl ├── CMakeLists.txt ├── CONTRIBUTORS.md ├── INSTALL.md ├── LICENSE ├── Makefile ├── Makefile.config ├── Makefile.config.example ├── README.md ├── caffe.cloc ├── cmake │ ├── ConfigGen.cmake │ ├── Cuda.cmake │ ├── Dependencies.cmake │ ├── Misc.cmake │ ├── Modules │ │ ├── FindAtlas.cmake │ │ ├── FindGFlags.cmake │ │ ├── FindGlog.cmake │ │ ├── FindLAPACK.cmake │ │ ├── FindLMDB.cmake │ │ ├── FindLevelDB.cmake │ │ ├── FindMKL.cmake │ │ ├── FindMatlabMex.cmake │ │ ├── FindNumPy.cmake │ │ ├── FindOpenBLAS.cmake │ │ ├── FindSnappy.cmake │ │ └── FindvecLib.cmake │ ├── ProtoBuf.cmake │ ├── Summary.cmake │ ├── Targets.cmake │ ├── Templates │ │ ├── CaffeConfig.cmake.in │ │ ├── CaffeConfigVersion.cmake.in │ │ └── caffe_config.h.in │ ├── Utils.cmake │ └── lint.cmake ├── data │ ├── cifar10 │ │ └── get_cifar10.sh │ ├── ilsvrc12 │ │ └── get_ilsvrc_aux.sh │ └── mnist │ │ └── get_mnist.sh ├── docs │ ├── CMakeLists.txt │ ├── CNAME │ ├── README.md │ ├── _config.yml │ ├── _layouts │ │ └── default.html │ ├── development.md │ ├── images │ │ ├── GitHub-Mark-64px.png │ │ └── caffeine-icon.png │ ├── index.md │ ├── install_apt.md │ ├── install_osx.md │ ├── install_yum.md │ ├── installation.md │ ├── model_zoo.md │ ├── performance_hardware.md │ ├── stylesheets │ │ ├── pygment_trac.css │ │ ├── reset.css │ │ └── styles.css │ └── tutorial │ │ ├── convolution.md │ │ ├── data.md │ │ ├── fig │ │ ├── backward.jpg │ │ ├── forward.jpg │ │ ├── forward_backward.png │ │ ├── layer.jpg │ │ └── logreg.jpg │ │ ├── forward_backward.md │ │ ├── index.md │ │ ├── interfaces.md │ │ ├── layers.md │ │ ├── loss.md │ │ ├── net_layer_blob.md │ │ └── solver.md ├── examples │ ├── CMakeLists.txt │ ├── cifar10 │ │ ├── cifar10_full.prototxt │ │ ├── cifar10_full_solver.prototxt │ │ ├── cifar10_full_solver_lr1.prototxt │ │ ├── cifar10_full_solver_lr2.prototxt │ │ ├── cifar10_full_train_test.prototxt │ │ ├── cifar10_quick.prototxt │ │ ├── cifar10_quick_solver.prototxt │ │ ├── cifar10_quick_solver_lr1.prototxt │ │ ├── cifar10_quick_train_test.prototxt │ │ ├── convert_cifar_data.cpp │ │ ├── create_cifar10.sh │ │ ├── readme.md │ │ ├── train_full.sh │ │ └── train_quick.sh │ ├── classification.ipynb │ ├── detection.ipynb │ ├── feature_extraction │ │ ├── imagenet_val.prototxt │ │ └── readme.md │ ├── filter_visualization.ipynb │ ├── finetune_flickr_style │ │ ├── assemble_data.py │ │ ├── flickr_style.csv.gz │ │ ├── readme.md │ │ └── style_names.txt │ ├── finetune_pascal_detection │ │ ├── pascal_finetune_solver.prototxt │ │ └── pascal_finetune_trainval_test.prototxt │ ├── hdf5_classification.ipynb │ ├── hdf5_classification │ │ ├── solver.prototxt │ │ ├── solver2.prototxt │ │ ├── train_val.prototxt │ │ └── train_val2.prototxt │ ├── imagenet │ │ ├── create_imagenet.sh │ │ ├── make_imagenet_mean.sh │ │ ├── readme.md │ │ ├── resume_training.sh │ │ └── train_caffenet.sh │ ├── images │ │ ├── cat.jpg │ │ ├── cat_gray.jpg │ │ └── fish-bike.jpg │ ├── mnist │ │ ├── convert_mnist_data.cpp │ │ ├── create_mnist.sh │ │ ├── lenet.prototxt │ │ ├── lenet_consolidated_solver.prototxt │ │ ├── lenet_multistep_solver.prototxt │ │ ├── lenet_solver.prototxt │ │ ├── lenet_stepearly_solver.prototxt │ │ ├── lenet_train_test.prototxt │ │ ├── mnist_autoencoder.prototxt │ │ ├── mnist_autoencoder_solver.prototxt │ │ ├── mnist_autoencoder_solver_adagrad.prototxt │ │ ├── mnist_autoencoder_solver_nesterov.prototxt │ │ ├── readme.md │ │ ├── train_lenet.sh │ │ ├── train_lenet_consolidated.sh │ │ ├── train_mnist_autoencoder.sh │ │ ├── train_mnist_autoencoder_adagrad.sh │ │ └── train_mnist_autoencoder_nesterov.sh │ ├── net_surgery.ipynb │ ├── net_surgery │ │ ├── bvlc_caffenet_full_conv.prototxt │ │ └── conv.prototxt │ ├── siamese │ │ ├── convert_mnist_siamese_data.cpp │ │ ├── create_mnist_siamese.sh │ │ ├── mnist_siamese.ipynb │ │ ├── mnist_siamese.prototxt │ │ ├── mnist_siamese_solver.prototxt │ │ ├── mnist_siamese_train_test.prototxt │ │ ├── readme.md │ │ └── train_mnist_siamese.sh │ └── web_demo │ │ ├── app.py │ │ ├── exifutil.py │ │ ├── readme.md │ │ ├── requirements.txt │ │ └── templates │ │ └── index.html ├── google │ └── protobuf │ │ ├── any.h │ │ ├── any.pb.h │ │ ├── any.proto │ │ ├── api.pb.h │ │ ├── api.proto │ │ ├── arena.h │ │ ├── arenastring.h │ │ ├── compiler │ │ ├── code_generator.h │ │ ├── command_line_interface.h │ │ ├── cpp │ │ │ └── cpp_generator.h │ │ ├── csharp │ │ │ ├── csharp_generator.h │ │ │ └── csharp_names.h │ │ ├── importer.h │ │ ├── java │ │ │ ├── java_generator.h │ │ │ └── java_names.h │ │ ├── javanano │ │ │ └── javanano_generator.h │ │ ├── objectivec │ │ │ ├── objectivec_generator.h │ │ │ └── objectivec_helpers.h │ │ ├── parser.h │ │ ├── plugin.h │ │ ├── plugin.pb.h │ │ ├── plugin.proto │ │ ├── python │ │ │ └── python_generator.h │ │ └── ruby │ │ │ └── ruby_generator.h │ │ ├── descriptor.h │ │ ├── descriptor.pb.h │ │ ├── descriptor.proto │ │ ├── descriptor_database.h │ │ ├── duration.pb.h │ │ ├── duration.proto │ │ ├── dynamic_message.h │ │ ├── empty.pb.h │ │ ├── empty.proto │ │ ├── extension_set.h │ │ ├── field_mask.pb.h │ │ ├── field_mask.proto │ │ ├── generated_enum_reflection.h │ │ ├── generated_enum_util.h │ │ ├── generated_message_reflection.h │ │ ├── generated_message_util.h │ │ ├── io │ │ ├── coded_stream.h │ │ ├── gzip_stream.h │ │ ├── printer.h │ │ ├── strtod.h │ │ ├── tokenizer.h │ │ ├── zero_copy_stream.h │ │ ├── zero_copy_stream_impl.h │ │ └── zero_copy_stream_impl_lite.h │ │ ├── map.h │ │ ├── map_entry.h │ │ ├── map_entry_lite.h │ │ ├── map_field.h │ │ ├── map_field_inl.h │ │ ├── map_field_lite.h │ │ ├── map_type_handler.h │ │ ├── message.h │ │ ├── message_lite.h │ │ ├── metadata.h │ │ ├── reflection.h │ │ ├── reflection_ops.h │ │ ├── repeated_field.h │ │ ├── repeated_field_reflection.h │ │ ├── service.h │ │ ├── source_context.pb.h │ │ ├── source_context.proto │ │ ├── struct.pb.h │ │ ├── struct.proto │ │ ├── stubs │ │ ├── atomic_sequence_num.h │ │ ├── atomicops.h │ │ ├── atomicops_internals_aix.h │ │ ├── atomicops_internals_arm64_gcc.h │ │ ├── atomicops_internals_arm_gcc.h │ │ ├── atomicops_internals_arm_qnx.h │ │ ├── atomicops_internals_atomicword_compat.h │ │ ├── atomicops_internals_generic_gcc.h │ │ ├── atomicops_internals_macosx.h │ │ ├── atomicops_internals_mips_gcc.h │ │ ├── atomicops_internals_pnacl.h │ │ ├── atomicops_internals_solaris.h │ │ ├── atomicops_internals_tsan.h │ │ ├── atomicops_internals_x86_gcc.h │ │ ├── atomicops_internals_x86_msvc.h │ │ ├── bytestream.h │ │ ├── callback.h │ │ ├── casts.h │ │ ├── common.h │ │ ├── fastmem.h │ │ ├── hash.h │ │ ├── logging.h │ │ ├── macros.h │ │ ├── mutex.h │ │ ├── once.h │ │ ├── platform_macros.h │ │ ├── port.h │ │ ├── scoped_ptr.h │ │ ├── shared_ptr.h │ │ ├── singleton.h │ │ ├── status.h │ │ ├── stl_util.h │ │ ├── stringpiece.h │ │ ├── template_util.h │ │ └── type_traits.h │ │ ├── text_format.h │ │ ├── timestamp.pb.h │ │ ├── timestamp.proto │ │ ├── type.pb.h │ │ ├── type.proto │ │ ├── unknown_field_set.h │ │ ├── util │ │ ├── field_comparator.h │ │ ├── field_mask_util.h │ │ ├── json_util.h │ │ ├── message_differencer.h │ │ ├── time_util.h │ │ ├── type_resolver.h │ │ └── type_resolver_util.h │ │ ├── wire_format.h │ │ ├── wire_format_lite.h │ │ ├── wire_format_lite_inl.h │ │ ├── wrappers.pb.h │ │ └── wrappers.proto ├── include │ └── caffe │ │ ├── blob.hpp │ │ ├── caffe.hpp │ │ ├── common.hpp │ │ ├── common_layers.hpp │ │ ├── data_layers.hpp │ │ ├── data_transformer.hpp │ │ ├── fast_rcnn_layers.hpp │ │ ├── filler.hpp │ │ ├── internal_thread.hpp │ │ ├── layer.hpp │ │ ├── layer_factory.hpp │ │ ├── loss_layers.hpp │ │ ├── net.hpp │ │ ├── neuron_layers.hpp │ │ ├── proto │ │ ├── caffe.pb.cc.bk │ │ ├── caffe.pb.h.bk │ │ └── caffe.proto │ │ ├── python_layer.hpp │ │ ├── solver.hpp │ │ ├── syncedmem.hpp │ │ ├── test │ │ ├── test_caffe_main.hpp │ │ └── test_gradient_check_util.hpp │ │ ├── util │ │ ├── benchmark.hpp │ │ ├── cudnn.hpp │ │ ├── db.hpp │ │ ├── device_alternate.hpp │ │ ├── im2col.hpp │ │ ├── insert_splits.hpp │ │ ├── io.hpp │ │ ├── math_functions.hpp │ │ ├── mkl_alternate.hpp │ │ ├── rng.hpp │ │ └── upgrade_proto.hpp │ │ └── vision_layers.hpp ├── matlab │ ├── CMakeLists.txt │ └── caffe │ │ ├── caffe.mexa64 │ │ ├── hdf5creation │ │ ├── demo.m │ │ └── store2hdf5.m │ │ ├── ilsvrc_2012_mean.mat │ │ ├── matcaffe.cpp │ │ ├── matcaffe_batch.m │ │ ├── matcaffe_demo.m │ │ ├── matcaffe_demo_vgg.m │ │ ├── matcaffe_demo_vgg_mean_pix.m │ │ ├── matcaffe_init.m │ │ ├── prepare_batch.m │ │ ├── print_cell.m │ │ └── read_cell.m ├── models │ ├── bvlc_alexnet │ │ ├── deploy.prototxt │ │ ├── readme.md │ │ ├── solver.prototxt │ │ └── train_val.prototxt │ ├── bvlc_googlenet │ │ ├── deploy.prototxt │ │ ├── quick_solver.prototxt │ │ ├── readme.md │ │ ├── solver.prototxt │ │ └── train_val.prototxt │ ├── bvlc_reference_caffenet │ │ ├── deploy.prototxt │ │ ├── readme.md │ │ ├── solver.prototxt │ │ └── train_val.prototxt │ ├── bvlc_reference_rcnn_ilsvrc13 │ │ ├── deploy.prototxt │ │ └── readme.md │ └── finetune_flickr_style │ │ ├── deploy.prototxt │ │ ├── readme.md │ │ ├── solver.prototxt │ │ └── train_val.prototxt ├── python │ ├── CMakeLists.txt │ ├── caffe │ │ ├── __init__.py │ │ ├── __init__.pyc │ │ ├── _caffe.cpp │ │ ├── _caffe.so │ │ ├── classifier.py │ │ ├── classifier.pyc │ │ ├── detector.py │ │ ├── detector.pyc │ │ ├── draw.py │ │ ├── imagenet │ │ │ └── ilsvrc_2012_mean.npy │ │ ├── io.py │ │ ├── io.pyc │ │ ├── proto │ │ │ ├── __init__.pyc │ │ │ ├── caffe_pb2.py │ │ │ └── caffe_pb2.pyc │ │ ├── pycaffe.py │ │ ├── pycaffe.pyc │ │ └── test │ │ │ ├── test_net.py │ │ │ ├── test_python_layer.py │ │ │ ├── test_python_layer_with_param_str.py │ │ │ └── test_solver.py │ ├── classify.py │ ├── detect.py │ ├── draw_net.py │ └── requirements.txt ├── scripts │ ├── build_docs.sh │ ├── copy_notebook.py │ ├── cpp_lint.py │ ├── deploy_docs.sh │ ├── download_model_binary.py │ ├── download_model_from_gist.sh │ ├── gather_examples.sh │ ├── travis │ │ ├── travis_build_and_test.sh │ │ ├── travis_install.sh │ │ └── travis_setup_makefile_config.sh │ └── upload_model_to_gist.sh ├── src │ ├── caffe │ │ ├── CMakeLists.txt │ │ ├── blob.cpp │ │ ├── common.cpp │ │ ├── data_transformer.cpp │ │ ├── internal_thread.cpp │ │ ├── layer_factory.cpp │ │ ├── layers │ │ │ ├── absval_layer.cpp │ │ │ ├── absval_layer.cu │ │ │ ├── accuracy_layer.cpp │ │ │ ├── argmax_layer.cpp │ │ │ ├── base_conv_layer.cpp │ │ │ ├── base_data_layer.cpp │ │ │ ├── base_data_layer.cu │ │ │ ├── bnll_layer.cpp │ │ │ ├── bnll_layer.cu │ │ │ ├── concat_layer.cpp │ │ │ ├── concat_layer.cu │ │ │ ├── contrastive_loss_layer.cpp │ │ │ ├── contrastive_loss_layer.cu │ │ │ ├── conv_layer.cpp │ │ │ ├── conv_layer.cu │ │ │ ├── cudnn_conv_layer.cpp │ │ │ ├── cudnn_conv_layer.cu │ │ │ ├── cudnn_pooling_layer.cpp │ │ │ ├── cudnn_pooling_layer.cu │ │ │ ├── cudnn_relu_layer.cpp │ │ │ ├── cudnn_relu_layer.cu │ │ │ ├── cudnn_sigmoid_layer.cpp │ │ │ ├── cudnn_sigmoid_layer.cu │ │ │ ├── cudnn_softmax_layer.cpp │ │ │ ├── cudnn_softmax_layer.cu │ │ │ ├── cudnn_tanh_layer.cpp │ │ │ ├── cudnn_tanh_layer.cu │ │ │ ├── data_layer.cpp │ │ │ ├── deconv_layer.cpp │ │ │ ├── deconv_layer.cu │ │ │ ├── dropout_layer.cpp │ │ │ ├── dropout_layer.cu │ │ │ ├── dummy_data_layer.cpp │ │ │ ├── eltwise_layer.cpp │ │ │ ├── eltwise_layer.cu │ │ │ ├── euclidean_loss_layer.cpp │ │ │ ├── euclidean_loss_layer.cu │ │ │ ├── exp_layer.cpp │ │ │ ├── exp_layer.cu │ │ │ ├── flatten_layer.cpp │ │ │ ├── hdf5_data_layer.cpp │ │ │ ├── hdf5_data_layer.cu │ │ │ ├── hdf5_output_layer.cpp │ │ │ ├── hdf5_output_layer.cu │ │ │ ├── hinge_loss_layer.cpp │ │ │ ├── im2col_layer.cpp │ │ │ ├── im2col_layer.cu │ │ │ ├── image_data_layer.cpp │ │ │ ├── infogain_loss_layer.cpp │ │ │ ├── inner_product_layer.cpp │ │ │ ├── inner_product_layer.cu │ │ │ ├── loss_layer.cpp │ │ │ ├── lrn_layer.cpp │ │ │ ├── lrn_layer.cu │ │ │ ├── memory_data_layer.cpp │ │ │ ├── multinomial_logistic_loss_layer.cpp │ │ │ ├── mvn_layer.cpp │ │ │ ├── mvn_layer.cu │ │ │ ├── neuron_layer.cpp │ │ │ ├── pooling_layer.cpp │ │ │ ├── pooling_layer.cu │ │ │ ├── power_layer.cpp │ │ │ ├── power_layer.cu │ │ │ ├── prelu_layer.cpp │ │ │ ├── prelu_layer.cu │ │ │ ├── relu_layer.cpp │ │ │ ├── relu_layer.cu │ │ │ ├── roi_pooling_layer.cpp │ │ │ ├── roi_pooling_layer.cu │ │ │ ├── sigmoid_cross_entropy_loss_layer.cpp │ │ │ ├── sigmoid_cross_entropy_loss_layer.cu │ │ │ ├── sigmoid_layer.cpp │ │ │ ├── sigmoid_layer.cu │ │ │ ├── silence_layer.cpp │ │ │ ├── silence_layer.cu │ │ │ ├── slice_layer.cpp │ │ │ ├── slice_layer.cu │ │ │ ├── smooth_L1_loss_layer.cpp │ │ │ ├── smooth_L1_loss_layer.cu │ │ │ ├── softmax_layer.cpp │ │ │ ├── softmax_layer.cu │ │ │ ├── softmax_loss_layer.cpp │ │ │ ├── softmax_loss_layer.cu │ │ │ ├── softmax_pair_layer.cpp │ │ │ ├── softmax_pair_loss_layer.cpp │ │ │ ├── split_layer.cpp │ │ │ ├── split_layer.cu │ │ │ ├── tanh_layer.cpp │ │ │ ├── tanh_layer.cu │ │ │ ├── threshold_layer.cpp │ │ │ ├── threshold_layer.cu │ │ │ └── window_data_layer.cpp │ │ ├── net.cpp │ │ ├── proto │ │ │ ├── caffe.pb.cc │ │ │ ├── caffe.pb.cc.bk │ │ │ ├── caffe.pb.h │ │ │ ├── caffe.pb.h.bk │ │ │ └── caffe.proto │ │ ├── solver.cpp │ │ ├── syncedmem.cpp │ │ ├── test │ │ │ ├── CMakeLists.txt │ │ │ ├── test_accuracy_layer.cpp │ │ │ ├── test_argmax_layer.cpp │ │ │ ├── test_benchmark.cpp │ │ │ ├── test_blob.cpp │ │ │ ├── test_caffe_main.cpp │ │ │ ├── test_common.cpp │ │ │ ├── test_concat_layer.cpp │ │ │ ├── test_contrastive_loss_layer.cpp │ │ │ ├── test_convolution_layer.cpp │ │ │ ├── test_data │ │ │ │ ├── generate_sample_data.py │ │ │ │ ├── sample_data.h5 │ │ │ │ ├── sample_data_2_gzip.h5 │ │ │ │ └── sample_data_list.txt │ │ │ ├── test_data_layer.cpp │ │ │ ├── test_data_transformer.cpp │ │ │ ├── test_db.cpp │ │ │ ├── test_deconvolution_layer.cpp │ │ │ ├── test_dummy_data_layer.cpp │ │ │ ├── test_eltwise_layer.cpp │ │ │ ├── test_euclidean_loss_layer.cpp │ │ │ ├── test_filler.cpp │ │ │ ├── test_flatten_layer.cpp │ │ │ ├── test_gradient_based_solver.cpp │ │ │ ├── test_hdf5_output_layer.cpp │ │ │ ├── test_hdf5data_layer.cpp │ │ │ ├── test_hinge_loss_layer.cpp │ │ │ ├── test_im2col_kernel.cu │ │ │ ├── test_im2col_layer.cpp │ │ │ ├── test_image_data_layer.cpp │ │ │ ├── test_infogain_loss_layer.cpp │ │ │ ├── test_inner_product_layer.cpp │ │ │ ├── test_internal_thread.cpp │ │ │ ├── test_io.cpp │ │ │ ├── test_layer_factory.cpp │ │ │ ├── test_lrn_layer.cpp │ │ │ ├── test_math_functions.cpp │ │ │ ├── test_maxpool_dropout_layers.cpp │ │ │ ├── test_memory_data_layer.cpp │ │ │ ├── test_multinomial_logistic_loss_layer.cpp │ │ │ ├── test_mvn_layer.cpp │ │ │ ├── test_net.cpp │ │ │ ├── test_neuron_layer.cpp │ │ │ ├── test_platform.cpp │ │ │ ├── test_pooling_layer.cpp │ │ │ ├── test_power_layer.cpp │ │ │ ├── test_protobuf.cpp │ │ │ ├── test_random_number_generator.cpp │ │ │ ├── test_roi_pooling_layer.cpp │ │ │ ├── test_sigmoid_cross_entropy_loss_layer.cpp │ │ │ ├── test_slice_layer.cpp │ │ │ ├── test_softmax_layer.cpp │ │ │ ├── test_softmax_with_loss_layer.cpp │ │ │ ├── test_solver.cpp │ │ │ ├── test_split_layer.cpp │ │ │ ├── test_stochastic_pooling.cpp │ │ │ ├── test_syncedmem.cpp │ │ │ ├── test_tanh_layer.cpp │ │ │ ├── test_threshold_layer.cpp │ │ │ ├── test_upgrade_proto.cpp │ │ │ └── test_util_blas.cpp │ │ └── util │ │ │ ├── benchmark.cpp │ │ │ ├── cudnn.cpp │ │ │ ├── db.cpp │ │ │ ├── im2col.cpp │ │ │ ├── im2col.cu │ │ │ ├── insert_splits.cpp │ │ │ ├── io.cpp │ │ │ ├── math_functions.cpp │ │ │ ├── math_functions.cu │ │ │ └── upgrade_proto.cpp │ └── gtest │ │ ├── CMakeLists.txt │ │ ├── gtest-all.cpp │ │ ├── gtest.h │ │ └── gtest_main.cc └── tools │ ├── CMakeLists.txt │ ├── caffe.cpp │ ├── compute_image_mean.cpp │ ├── convert_imageset.cpp │ ├── device_query.cpp │ ├── extra │ ├── extract_seconds.py │ ├── launch_resize_and_crop_images.sh │ ├── parse_log.py │ ├── parse_log.sh │ ├── plot_log.gnuplot.example │ ├── plot_training_log.py.example │ └── resize_and_crop_images.py │ ├── extract_features.cpp │ ├── finetune_net.cpp │ ├── net_speed_benchmark.cpp │ ├── test_net.cpp │ ├── train_net.cpp │ ├── upgrade_net_proto_binary.cpp │ └── upgrade_net_proto_text.cpp ├── cls_adapt.sh ├── data ├── edgebox_data │ └── README.md ├── imagenet_models │ └── README.md └── pylintrc ├── det_adapt.sh ├── features ├── cache_bb_features.m ├── cache_fc7_features.m ├── cache_fc8_features.m ├── extract_region_in.m ├── extract_region_out.m ├── extract_regions.m └── preprocess.m ├── imdb ├── cache │ └── README.md ├── get_voc_opts.m ├── imdb_eval_voc.m ├── imdb_from_voc.m └── roidb_from_voc.m ├── lib ├── Makefile ├── datasets │ ├── VOCdevkit-matlab-wrapper │ │ ├── get_voc_opts.m │ │ ├── voc_eval.m │ │ └── xVOCap.m │ ├── __init__.py │ ├── __init__.pyc │ ├── factory.py │ ├── factory.pyc │ ├── imdb.py │ ├── imdb.pyc │ ├── pascal_voc.py │ └── pascal_voc.pyc ├── fast_rcnn │ ├── __init__.py │ ├── __init__.pyc │ ├── config.py │ ├── config.pyc │ ├── test.py │ ├── test.pyc │ ├── train.py │ └── train.pyc ├── roi_data_layer │ ├── __init__.py │ ├── __init__.pyc │ ├── layer.py │ ├── layer.pyc │ ├── minibatch.py │ ├── minibatch.pyc │ ├── roidb.py │ └── roidb.pyc ├── setup.py └── utils │ ├── __init__.py │ ├── __init__.pyc │ ├── bbox.c │ ├── bbox.pyx │ ├── blob.py │ ├── blob.pyc │ ├── cython_bbox.so │ ├── cython_nms.so │ ├── nms.c │ ├── nms.py │ ├── nms.pyx │ ├── timer.py │ └── timer.pyc ├── maskout.m ├── mil.m ├── mil ├── SVM_Cost_L1hinge.m ├── SVM_Cost_Logistic.m ├── SVM_Cost_SmoothHinge.m ├── cluster_patches_parallel_single_nogt_20x1.m ├── feat_stats_hos.m ├── general_smooth_hinge.m ├── load_cached_features_hos.m ├── mil_classes_20x1_smooth_lsvm_topK_bagmine_greedycover.m ├── mil_region_mining.m ├── minFunc_2012 │ ├── autoDif │ │ ├── autoGrad.m │ │ ├── autoHess.m │ │ ├── autoHv.m │ │ ├── autoTensor.m │ │ ├── derivativeCheck.m │ │ └── fastDerivativeCheck.m │ ├── example_derivativeCheck.m │ ├── example_minFunc.m │ ├── logisticExample │ │ ├── LogisticDiagPrecond.m │ │ ├── LogisticHv.m │ │ ├── LogisticLoss.m │ │ ├── example_minFunc_LR.m │ │ └── mylogsumexp.m │ ├── mexAll.m │ ├── minFunc │ │ ├── ArmijoBacktrack.m │ │ ├── WolfeLineSearch.m │ │ ├── compiled │ │ │ ├── lbfgsAddC.mexa64 │ │ │ ├── lbfgsAddC.mexmaci64 │ │ │ ├── lbfgsAddC.mexw64 │ │ │ ├── lbfgsC.mexa64 │ │ │ ├── lbfgsC.mexglx │ │ │ ├── lbfgsC.mexmac │ │ │ ├── lbfgsC.mexmaci │ │ │ ├── lbfgsC.mexmaci64 │ │ │ ├── lbfgsC.mexw32 │ │ │ ├── lbfgsC.mexw64 │ │ │ ├── lbfgsProdC.mexa64 │ │ │ ├── lbfgsProdC.mexmaci64 │ │ │ ├── lbfgsProdC.mexw64 │ │ │ ├── mcholC.mexa64 │ │ │ ├── mcholC.mexglx │ │ │ ├── mcholC.mexmac │ │ │ ├── mcholC.mexmaci64 │ │ │ ├── mcholC.mexw32 │ │ │ └── mcholC.mexw64 │ │ ├── conjGrad.m │ │ ├── dampedUpdate.m │ │ ├── isLegal.m │ │ ├── lbfgs.m │ │ ├── lbfgsAdd.m │ │ ├── lbfgsProd.m │ │ ├── lbfgsUpdate.m │ │ ├── mchol.m │ │ ├── mcholinc.m │ │ ├── mex │ │ │ ├── lbfgsAddC.c │ │ │ ├── lbfgsC.c │ │ │ ├── lbfgsProdC.c │ │ │ └── mcholC.c │ │ ├── minFunc.m │ │ ├── minFunc_processInputOptions.m │ │ ├── polyinterp.m │ │ ├── precondDiag.m │ │ ├── precondTriu.m │ │ ├── precondTriuDiag.m │ │ └── taylorModel.m │ └── rosenbrock.m ├── projsplx │ ├── license.txt │ ├── projsplx_c_float.cc │ ├── projsplx_c_float.mexa64 │ └── projsplx_c_float.mexmaci64 ├── slslvm_cost_smoothhinge_bagmine.m ├── train_classes_20x1_smooth_greedycover.m ├── train_classes_20x1_smooth_lsvm_topK_bagmine_greedycover.m ├── voc_config.m └── xform_feat_custom.m ├── output └── default │ └── README.md ├── prepare_for_cls_adapt.m ├── prepare_for_det_adapt.m ├── prototxt ├── caffenet_fc7.prototxt ├── caffenet_fc8.prototxt ├── cls_adapt_solver.prototxt ├── cls_adapt_train.prototxt ├── det_adapt_solver.prototxt ├── det_adapt_train.prototxt └── test.prototxt ├── startup.m ├── test.sh ├── tools └── extra │ ├── _init_paths.py │ ├── _init_paths.pyc │ ├── reval.py │ ├── test_net.py │ ├── train_net.py │ └── train_svms.py ├── utils ├── boxoverlap.m ├── cmp_feat_caches.m ├── create_folds.m ├── fc8_model.m ├── grid_search.m ├── hdf5_dir_to_mat_dir.m ├── link_train_val.m ├── load_h5.m ├── mkdir_if_missing.m ├── nms.m ├── procid.m ├── receptive_field_size.m ├── receptive_field_sizes.m ├── report.m ├── seed_rand.m ├── test_2010_from_2012.m ├── tic_toc_print.m ├── verify_caffe_crops.m ├── x10VOCevaldet.m ├── xVOCap.m ├── xVOChash_init.m └── xVOChash_lookup.m ├── vis ├── browse_saved_boxes.m ├── fig_training_samples.m ├── pick_feature_pair.m ├── pool5-explorer │ ├── pool5_explorer.m │ └── pool5_explorer_build_index.m ├── rank_by_feature.m ├── rank_by_feature_pair.m ├── sample_correlated_pairs.m ├── show_detections.m ├── show_latent_choice.m ├── showboxes.m ├── showboxes_hos.m ├── showboxesc.m ├── viewerrors.m ├── vis_crops.m └── vis_test_dets.m └── voc_init.m /LICENSE: -------------------------------------------------------------------------------- 1 | WSL 2 | 3 | MIT License 4 | 5 | Copyright (c) 2016, Dong Li, Jia-Bin Huang 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /cache/README.md: -------------------------------------------------------------------------------- 1 | 2 | Extracted features are saved in this directory. 3 | -------------------------------------------------------------------------------- /caffe-wsl/CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | # Contributors 2 | 3 | Caffe is developed by a core set of BVLC members and the open-source community. 4 | 5 | We thank all of our [contributors](https://github.com/BVLC/caffe/graphs/contributors)! 6 | 7 | **For the detailed history of contributions** of a given file, try 8 | 9 | git blame file 10 | 11 | to see line-by-line credits and 12 | 13 | git log --follow file 14 | 15 | to see the change log even across renames and rewrites. 16 | 17 | Please refer to the [acknowledgements](http://caffe.berkeleyvision.org/#acknowledgements) on the Caffe site for further details. 18 | 19 | **Copyright** is held by the original contributor according to the versioning history; see LICENSE. 20 | -------------------------------------------------------------------------------- /caffe-wsl/INSTALL.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | See http://caffe.berkeleyvision.org/installation.html for the latest 4 | installation instructions. 5 | 6 | Check the issue tracker in case you need help: 7 | https://github.com/BVLC/caffe/issues 8 | -------------------------------------------------------------------------------- /caffe-wsl/caffe.cloc: -------------------------------------------------------------------------------- 1 | Bourne Shell 2 | filter remove_matches ^\s*# 3 | filter remove_inline #.*$ 4 | extension sh 5 | script_exe sh 6 | C 7 | filter remove_matches ^\s*// 8 | filter call_regexp_common C 9 | filter remove_inline //.*$ 10 | extension c 11 | extension ec 12 | extension pgc 13 | C++ 14 | filter remove_matches ^\s*// 15 | filter remove_inline //.*$ 16 | filter call_regexp_common C 17 | extension C 18 | extension cc 19 | extension cpp 20 | extension cxx 21 | extension pcc 22 | C/C++ Header 23 | filter remove_matches ^\s*// 24 | filter call_regexp_common C 25 | filter remove_inline //.*$ 26 | extension H 27 | extension h 28 | extension hh 29 | extension hpp 30 | CUDA 31 | filter remove_matches ^\s*// 32 | filter remove_inline //.*$ 33 | filter call_regexp_common C 34 | extension cu 35 | Python 36 | filter remove_matches ^\s*# 37 | filter docstring_to_C 38 | filter call_regexp_common C 39 | filter remove_inline #.*$ 40 | extension py 41 | make 42 | filter remove_matches ^\s*# 43 | filter remove_inline #.*$ 44 | extension Gnumakefile 45 | extension Makefile 46 | extension am 47 | extension gnumakefile 48 | extension makefile 49 | filename Gnumakefile 50 | filename Makefile 51 | filename gnumakefile 52 | filename makefile 53 | script_exe make 54 | -------------------------------------------------------------------------------- /caffe-wsl/cmake/Modules/FindGlog.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Glog 2 | # 3 | # The following variables are optionally searched for defaults 4 | # GLOG_ROOT_DIR: Base directory where all GLOG components are found 5 | # 6 | # The following are set after configuration is done: 7 | # GLOG_FOUND 8 | # GLOG_INCLUDE_DIRS 9 | # GLOG_LIBRARIES 10 | # GLOG_LIBRARYRARY_DIRS 11 | 12 | include(FindPackageHandleStandardArgs) 13 | 14 | set(GLOG_ROOT_DIR "" CACHE PATH "Folder contains Google glog") 15 | 16 | if(WIN32) 17 | find_path(GLOG_INCLUDE_DIR glog/logging.h 18 | PATHS ${GLOG_ROOT_DIR}/src/windows) 19 | else() 20 | find_path(GLOG_INCLUDE_DIR glog/logging.h 21 | PATHS ${GLOG_ROOT_DIR}) 22 | endif() 23 | 24 | if(MSVC) 25 | find_library(GLOG_LIBRARY_RELEASE libglog_static 26 | PATHS ${GLOG_ROOT_DIR} 27 | PATH_SUFFIXES Release) 28 | 29 | find_library(GLOG_LIBRARY_DEBUG libglog_static 30 | PATHS ${GLOG_ROOT_DIR} 31 | PATH_SUFFIXES Debug) 32 | 33 | set(GLOG_LIBRARY optimized ${GLOG_LIBRARY_RELEASE} debug ${GLOG_LIBRARY_DEBUG}) 34 | else() 35 | find_library(GLOG_LIBRARY glog 36 | PATHS ${GLOG_ROOT_DIR} 37 | PATH_SUFFIXES lib lib64) 38 | endif() 39 | 40 | find_package_handle_standard_args(GLOG DEFAULT_MSG GLOG_INCLUDE_DIR GLOG_LIBRARY) 41 | 42 | if(GLOG_FOUND) 43 | set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR}) 44 | set(GLOG_LIBRARIES ${GLOG_LIBRARY}) 45 | message(STATUS "Found glog (include: ${GLOG_INCLUDE_DIR}, library: ${GLOG_LIBRARY})") 46 | mark_as_advanced(GLOG_ROOT_DIR GLOG_LIBRARY_RELEASE GLOG_LIBRARY_DEBUG 47 | GLOG_LIBRARY GLOG_INCLUDE_DIR) 48 | endif() 49 | -------------------------------------------------------------------------------- /caffe-wsl/cmake/Modules/FindLMDB.cmake: -------------------------------------------------------------------------------- 1 | # Try to find the LMBD libraries and headers 2 | # LMDB_FOUND - system has LMDB lib 3 | # LMDB_INCLUDE_DIR - the LMDB include directory 4 | # LMDB_LIBRARIES - Libraries needed to use LMDB 5 | 6 | # FindCWD based on FindGMP by: 7 | # Copyright (c) 2006, Laurent Montel, 8 | # 9 | # Redistribution and use is allowed according to the terms of the BSD license. 10 | 11 | # Adapted from FindCWD by: 12 | # Copyright 2013 Conrad Steenberg 13 | # Aug 31, 2013 14 | 15 | find_path(LMDB_INCLUDE_DIR NAMES lmdb.h PATHS "$ENV{LMDB_DIR}/include") 16 | find_library(LMDB_LIBRARIES NAMES lmdb PATHS "$ENV{LMDB_DIR}/lib" ) 17 | 18 | include(FindPackageHandleStandardArgs) 19 | find_package_handle_standard_args(LMDB DEFAULT_MSG LMDB_INCLUDE_DIR LMDB_LIBRARIES) 20 | 21 | if(LMDB_FOUND) 22 | message(STATUS "Found lmdb (include: ${LMDB_INCLUDE_DIR}, library: ${LMDB_LIBRARIES})") 23 | mark_as_advanced(LMDB_INCLUDE_DIR LMDB_LIBRARIES) 24 | 25 | caffe_parse_header(${LMDB_INCLUDE_DIR}/lmdb.h 26 | LMDB_VERSION_LINES MDB_VERSION_MAJOR MDB_VERSION_MINOR MDB_VERSION_PATCH) 27 | set(LMDB_VERSION "${MDB_VERSION_MAJOR}.${MDB_VERSION_MINOR}.${MDB_VERSION_PATCH}") 28 | endif() 29 | -------------------------------------------------------------------------------- /caffe-wsl/cmake/Modules/FindSnappy.cmake: -------------------------------------------------------------------------------- 1 | # Find the Snappy libraries 2 | # 3 | # The following variables are optionally searched for defaults 4 | # Snappy_ROOT_DIR: Base directory where all Snappy components are found 5 | # 6 | # The following are set after configuration is done: 7 | # SNAPPY_FOUND 8 | # Snappy_INCLUDE_DIR 9 | # Snappy_LIBRARIES 10 | 11 | find_path(Snappy_INCLUDE_DIR NAMES snappy.h 12 | PATHS ${SNAPPY_ROOT_DIR} ${SNAPPY_ROOT_DIR}/include) 13 | 14 | find_library(Snappy_LIBRARIES NAMES snappy 15 | PATHS ${SNAPPY_ROOT_DIR} ${SNAPPY_ROOT_DIR}/lib) 16 | 17 | include(FindPackageHandleStandardArgs) 18 | find_package_handle_standard_args(Snappy DEFAULT_MSG Snappy_INCLUDE_DIR Snappy_LIBRARIES) 19 | 20 | if(SNAPPY_FOUND) 21 | message(STATUS "Found Snappy (include: ${Snappy_INCLUDE_DIR}, library: ${Snappy_LIBRARIES})") 22 | mark_as_advanced(Snappy_INCLUDE_DIR Snappy_LIBRARIES) 23 | 24 | caffe_parse_header(${Snappy_INCLUDE_DIR}/snappy-stubs-public.h 25 | SNAPPY_VERION_LINES SNAPPY_MAJOR SNAPPY_MINOR SNAPPY_PATCHLEVEL) 26 | set(Snappy_VERSION "${SNAPPY_MAJOR}.${SNAPPY_MINOR}.${SNAPPY_PATCHLEVEL}") 27 | endif() 28 | 29 | -------------------------------------------------------------------------------- /caffe-wsl/cmake/Modules/FindvecLib.cmake: -------------------------------------------------------------------------------- 1 | # Find the vecLib libraries as part of Accelerate.framework or as standalon framework 2 | # 3 | # The following are set after configuration is done: 4 | # VECLIB_FOUND 5 | # vecLib_INCLUDE_DIR 6 | # vecLib_LINKER_LIBS 7 | 8 | 9 | if(NOT APPLE) 10 | return() 11 | endif() 12 | 13 | set(__veclib_include_suffix "Frameworks/vecLib.framework/Versions/Current/Headers") 14 | 15 | find_path(vecLib_INCLUDE_DIR vecLib.h 16 | DOC "vecLib include directory" 17 | PATHS /System/Library/${__veclib_include_suffix} 18 | /System/Library/Frameworks/Accelerate.framework/Versions/Current/${__veclib_include_suffix} 19 | /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Headers/) 20 | 21 | include(FindPackageHandleStandardArgs) 22 | find_package_handle_standard_args(vecLib DEFAULT_MSG vecLib_INCLUDE_DIR) 23 | 24 | if(VECLIB_FOUND) 25 | if(vecLib_INCLUDE_DIR MATCHES "^/System/Library/Frameworks/vecLib.framework.*") 26 | set(vecLib_LINKER_LIBS -lcblas "-framework vecLib") 27 | message(STATUS "Found standalone vecLib.framework") 28 | else() 29 | set(vecLib_LINKER_LIBS -lcblas "-framework Accelerate") 30 | message(STATUS "Found vecLib as part of Accelerate.framework") 31 | endif() 32 | 33 | mark_as_advanced(vecLib_INCLUDE_DIR) 34 | endif() 35 | -------------------------------------------------------------------------------- /caffe-wsl/cmake/Templates/CaffeConfigVersion.cmake.in: -------------------------------------------------------------------------------- 1 | set(PACKAGE_VERSION "@Caffe_VERSION@") 2 | 3 | # Check whether the requested PACKAGE_FIND_VERSION is compatible 4 | if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") 5 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 6 | else() 7 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 8 | if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") 9 | set(PACKAGE_VERSION_EXACT TRUE) 10 | endif() 11 | endif() 12 | -------------------------------------------------------------------------------- /caffe-wsl/cmake/Templates/caffe_config.h.in: -------------------------------------------------------------------------------- 1 | /* Sources directory */ 2 | #define SOURCE_FOLDER "${PROJECT_SOURCE_DIR}" 3 | 4 | /* Binaries directory */ 5 | #define BINARY_FOLDER "${PROJECT_BINARY_DIR}" 6 | 7 | /* NVIDA Cuda */ 8 | #cmakedefine HAVE_CUDA 9 | 10 | /* NVIDA cuDNN */ 11 | #cmakedefine HAVE_CUDNN 12 | #cmakedefine USE_CUDNN 13 | 14 | /* NVIDA cuDNN */ 15 | #cmakedefine CPU_ONLY 16 | 17 | /* Test device */ 18 | #define CUDA_TEST_DEVICE ${CUDA_TEST_DEVICE} 19 | 20 | /* Temporary (TODO: remove) */ 21 | #if 1 22 | #define CMAKE_SOURCE_DIR SOURCE_FOLDER "/src/" 23 | #define EXAMPLES_SOURCE_DIR BINARY_FOLDER "/examples/" 24 | #define CMAKE_EXT ".gen.cmake" 25 | #else 26 | #define CMAKE_SOURCE_DIR "src/" 27 | #define EXAMPLES_SOURCE_DIR "examples/" 28 | #define CMAKE_EXT "" 29 | #endif 30 | 31 | /* Matlab */ 32 | #cmakedefine HAVE_MATLAB 33 | -------------------------------------------------------------------------------- /caffe-wsl/data/cifar10/get_cifar10.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # This scripts downloads the CIFAR10 (binary version) data and unzips it. 3 | 4 | DIR="$( cd "$(dirname "$0")" ; pwd -P )" 5 | cd $DIR 6 | 7 | echo "Downloading..." 8 | 9 | wget --no-check-certificate http://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz 10 | 11 | echo "Unzipping..." 12 | 13 | tar -xf cifar-10-binary.tar.gz && rm -f cifar-10-binary.tar.gz 14 | mv cifar-10-batches-bin/* . && rm -rf cifar-10-batches-bin 15 | 16 | # Creation is split out because leveldb sometimes causes segfault 17 | # and needs to be re-created. 18 | 19 | echo "Done." 20 | -------------------------------------------------------------------------------- /caffe-wsl/data/ilsvrc12/get_ilsvrc_aux.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # 3 | # N.B. This does not download the ilsvrcC12 data set, as it is gargantuan. 4 | # This script downloads the imagenet example auxiliary files including: 5 | # - the ilsvrc12 image mean, binaryproto 6 | # - synset ids and words 7 | # - Python pickle-format data of ImageNet graph structure and relative infogain 8 | # - the training splits with labels 9 | 10 | DIR="$( cd "$(dirname "$0")" ; pwd -P )" 11 | cd $DIR 12 | 13 | echo "Downloading..." 14 | 15 | wget http://dl.caffe.berkeleyvision.org/caffe_ilsvrc12.tar.gz 16 | 17 | echo "Unzipping..." 18 | 19 | tar -xf caffe_ilsvrc12.tar.gz && rm -f caffe_ilsvrc12.tar.gz 20 | 21 | echo "Done." 22 | -------------------------------------------------------------------------------- /caffe-wsl/data/mnist/get_mnist.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # This scripts downloads the mnist data and unzips it. 3 | 4 | DIR="$( cd "$(dirname "$0")" ; pwd -P )" 5 | cd $DIR 6 | 7 | echo "Downloading..." 8 | 9 | wget --no-check-certificate http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz 10 | wget --no-check-certificate http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz 11 | wget --no-check-certificate http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz 12 | wget --no-check-certificate http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz 13 | 14 | echo "Unzipping..." 15 | 16 | gunzip train-images-idx3-ubyte.gz 17 | gunzip train-labels-idx1-ubyte.gz 18 | gunzip t10k-images-idx3-ubyte.gz 19 | gunzip t10k-labels-idx1-ubyte.gz 20 | 21 | # Creation is split out because leveldb sometimes causes segfault 22 | # and needs to be re-created. 23 | 24 | echo "Done." 25 | -------------------------------------------------------------------------------- /caffe-wsl/docs/CNAME: -------------------------------------------------------------------------------- 1 | caffe.berkeleyvision.org 2 | -------------------------------------------------------------------------------- /caffe-wsl/docs/README.md: -------------------------------------------------------------------------------- 1 | # Caffe Documentation 2 | 3 | To generate the documentation, run `$CAFFE_ROOT/scripts/build_docs.sh`. 4 | 5 | To push your changes to the documentation to the gh-pages branch of your or the BVLC repo, run `$CAFFE_ROOT/scripts/deploy_docs.sh `. 6 | -------------------------------------------------------------------------------- /caffe-wsl/docs/_config.yml: -------------------------------------------------------------------------------- 1 | defaults: 2 | - 3 | scope: 4 | path: "" # an empty string here means all files in the project 5 | values: 6 | layout: "default" 7 | 8 | -------------------------------------------------------------------------------- /caffe-wsl/docs/images/GitHub-Mark-64px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/docs/images/GitHub-Mark-64px.png -------------------------------------------------------------------------------- /caffe-wsl/docs/images/caffeine-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/docs/images/caffeine-icon.png -------------------------------------------------------------------------------- /caffe-wsl/docs/stylesheets/reset.css: -------------------------------------------------------------------------------- 1 | /* MeyerWeb Reset */ 2 | 3 | html, body, div, span, applet, object, iframe, 4 | h1, h2, h3, h4, h5, h6, p, blockquote, pre, 5 | a, abbr, acronym, address, big, cite, code, 6 | del, dfn, em, img, ins, kbd, q, s, samp, 7 | small, strike, strong, sub, sup, tt, var, 8 | b, u, i, center, 9 | dl, dt, dd, ol, ul, li, 10 | fieldset, form, label, legend, 11 | table, caption, tbody, tfoot, thead, tr, th, td, 12 | article, aside, canvas, details, embed, 13 | figure, figcaption, footer, header, hgroup, 14 | menu, nav, output, ruby, section, summary, 15 | time, mark, audio, video { 16 | margin: 0; 17 | padding: 0; 18 | border: 0; 19 | font: inherit; 20 | vertical-align: baseline; 21 | } 22 | -------------------------------------------------------------------------------- /caffe-wsl/docs/tutorial/convolution.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Convolution 3 | --- 4 | # Caffeinated Convolution 5 | 6 | The Caffe strategy for convolution is to reduce the problem to matrix-matrix multiplication. 7 | This linear algebra computation is highly-tuned in BLAS libraries and efficiently computed on GPU devices. 8 | 9 | For more details read Yangqing's [Convolution in Caffe: a memo](https://github.com/Yangqing/caffe/wiki/Convolution-in-Caffe:-a-memo). 10 | 11 | As it turns out, this same reduction was independently explored in the context of conv. nets by 12 | 13 | > K. Chellapilla, S. Puri, P. Simard, et al. High performance convolutional neural networks for document processing. In Tenth International Workshop on Frontiers in Handwriting Recognition, 2006. 14 | -------------------------------------------------------------------------------- /caffe-wsl/docs/tutorial/fig/backward.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/docs/tutorial/fig/backward.jpg -------------------------------------------------------------------------------- /caffe-wsl/docs/tutorial/fig/forward.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/docs/tutorial/fig/forward.jpg -------------------------------------------------------------------------------- /caffe-wsl/docs/tutorial/fig/forward_backward.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/docs/tutorial/fig/forward_backward.png -------------------------------------------------------------------------------- /caffe-wsl/docs/tutorial/fig/layer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/docs/tutorial/fig/layer.jpg -------------------------------------------------------------------------------- /caffe-wsl/docs/tutorial/fig/logreg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/docs/tutorial/fig/logreg.jpg -------------------------------------------------------------------------------- /caffe-wsl/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB_RECURSE examples_srcs "${PROJECT_SOURCE_DIR}/examples/*.cpp") 2 | 3 | foreach(source_file ${examples_srcs}) 4 | # get file name 5 | get_filename_component(name ${source_file} NAME_WE) 6 | 7 | # get folder name 8 | get_filename_component(path ${source_file} PATH) 9 | get_filename_component(folder ${path} NAME_WE) 10 | 11 | add_executable(${name} ${source_file}) 12 | target_link_libraries(${name} ${Caffe_LINK}) 13 | caffe_default_properties(${name}) 14 | 15 | # set back RUNTIME_OUTPUT_DIRECTORY 16 | set_target_properties(${name} PROPERTIES 17 | RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/examples/${folder}") 18 | 19 | caffe_set_solution_folder(${name} examples) 20 | 21 | # install 22 | install(TARGETS ${name} DESTINATION bin) 23 | 24 | if(UNIX OR APPLE) 25 | # Funny command to make tutorials work 26 | # TODO: remove in future as soon as naming is standartaized everywhere 27 | set(__outname ${PROJECT_BINARY_DIR}/examples/${folder}/${name}${CAffe_POSTFIX}) 28 | add_custom_command(TARGET ${name} POST_BUILD 29 | COMMAND ln -sf "${__outname}" "${__outname}.bin") 30 | endif() 31 | endforeach() 32 | -------------------------------------------------------------------------------- /caffe-wsl/examples/cifar10/cifar10_full_solver.prototxt: -------------------------------------------------------------------------------- 1 | # reduce learning rate after 120 epochs (60000 iters) by factor 0f 10 2 | # then another factor of 10 after 10 more epochs (5000 iters) 3 | 4 | # The train/test net protocol buffer definition 5 | net: "examples/cifar10/cifar10_full_train_test.prototxt" 6 | # test_iter specifies how many forward passes the test should carry out. 7 | # In the case of CIFAR10, we have test batch size 100 and 100 test iterations, 8 | # covering the full 10,000 testing images. 9 | test_iter: 100 10 | # Carry out testing every 1000 training iterations. 11 | test_interval: 1000 12 | # The base learning rate, momentum and the weight decay of the network. 13 | base_lr: 0.001 14 | momentum: 0.9 15 | weight_decay: 0.004 16 | # The learning rate policy 17 | lr_policy: "fixed" 18 | # Display every 200 iterations 19 | display: 200 20 | # The maximum number of iterations 21 | max_iter: 60000 22 | # snapshot intermediate results 23 | snapshot: 10000 24 | snapshot_prefix: "examples/cifar10/cifar10_full" 25 | # solver mode: CPU or GPU 26 | solver_mode: GPU 27 | -------------------------------------------------------------------------------- /caffe-wsl/examples/cifar10/cifar10_full_solver_lr1.prototxt: -------------------------------------------------------------------------------- 1 | # reduce learning rate after 120 epochs (60000 iters) by factor 0f 10 2 | # then another factor of 10 after 10 more epochs (5000 iters) 3 | 4 | # The train/test net protocol buffer definition 5 | net: "examples/cifar10/cifar10_full_train_test.prototxt" 6 | # test_iter specifies how many forward passes the test should carry out. 7 | # In the case of CIFAR10, we have test batch size 100 and 100 test iterations, 8 | # covering the full 10,000 testing images. 9 | test_iter: 100 10 | # Carry out testing every 1000 training iterations. 11 | test_interval: 1000 12 | # The base learning rate, momentum and the weight decay of the network. 13 | base_lr: 0.0001 14 | momentum: 0.9 15 | weight_decay: 0.004 16 | # The learning rate policy 17 | lr_policy: "fixed" 18 | # Display every 200 iterations 19 | display: 200 20 | # The maximum number of iterations 21 | max_iter: 65000 22 | # snapshot intermediate results 23 | snapshot: 5000 24 | snapshot_prefix: "examples/cifar10/cifar10_full" 25 | # solver mode: CPU or GPU 26 | solver_mode: GPU 27 | -------------------------------------------------------------------------------- /caffe-wsl/examples/cifar10/cifar10_full_solver_lr2.prototxt: -------------------------------------------------------------------------------- 1 | # reduce learning rate after 120 epochs (60000 iters) by factor 0f 10 2 | # then another factor of 10 after 10 more epochs (5000 iters) 3 | 4 | # The train/test net protocol buffer definition 5 | net: "examples/cifar10/cifar10_full_train_test.prototxt" 6 | # test_iter specifies how many forward passes the test should carry out. 7 | # In the case of CIFAR10, we have test batch size 100 and 100 test iterations, 8 | # covering the full 10,000 testing images. 9 | test_iter: 100 10 | # Carry out testing every 1000 training iterations. 11 | test_interval: 1000 12 | # The base learning rate, momentum and the weight decay of the network. 13 | base_lr: 0.00001 14 | momentum: 0.9 15 | weight_decay: 0.004 16 | # The learning rate policy 17 | lr_policy: "fixed" 18 | # Display every 200 iterations 19 | display: 200 20 | # The maximum number of iterations 21 | max_iter: 70000 22 | # snapshot intermediate results 23 | snapshot: 5000 24 | snapshot_prefix: "examples/cifar10/cifar10_full" 25 | # solver mode: CPU or GPU 26 | solver_mode: GPU 27 | -------------------------------------------------------------------------------- /caffe-wsl/examples/cifar10/cifar10_quick_solver.prototxt: -------------------------------------------------------------------------------- 1 | # reduce the learning rate after 8 epochs (4000 iters) by a factor of 10 2 | 3 | # The train/test net protocol buffer definition 4 | net: "examples/cifar10/cifar10_quick_train_test.prototxt" 5 | # test_iter specifies how many forward passes the test should carry out. 6 | # In the case of MNIST, we have test batch size 100 and 100 test iterations, 7 | # covering the full 10,000 testing images. 8 | test_iter: 100 9 | # Carry out testing every 500 training iterations. 10 | test_interval: 500 11 | # The base learning rate, momentum and the weight decay of the network. 12 | base_lr: 0.001 13 | momentum: 0.9 14 | weight_decay: 0.004 15 | # The learning rate policy 16 | lr_policy: "fixed" 17 | # Display every 100 iterations 18 | display: 100 19 | # The maximum number of iterations 20 | max_iter: 4000 21 | # snapshot intermediate results 22 | snapshot: 4000 23 | snapshot_prefix: "examples/cifar10/cifar10_quick" 24 | # solver mode: CPU or GPU 25 | solver_mode: GPU 26 | -------------------------------------------------------------------------------- /caffe-wsl/examples/cifar10/cifar10_quick_solver_lr1.prototxt: -------------------------------------------------------------------------------- 1 | # reduce the learning rate after 8 epochs (4000 iters) by a factor of 10 2 | 3 | # The train/test net protocol buffer definition 4 | net: "examples/cifar10/cifar10_quick_train_test.prototxt" 5 | # test_iter specifies how many forward passes the test should carry out. 6 | # In the case of MNIST, we have test batch size 100 and 100 test iterations, 7 | # covering the full 10,000 testing images. 8 | test_iter: 100 9 | # Carry out testing every 500 training iterations. 10 | test_interval: 500 11 | # The base learning rate, momentum and the weight decay of the network. 12 | base_lr: 0.0001 13 | momentum: 0.9 14 | weight_decay: 0.004 15 | # The learning rate policy 16 | lr_policy: "fixed" 17 | # Display every 100 iterations 18 | display: 100 19 | # The maximum number of iterations 20 | max_iter: 5000 21 | # snapshot intermediate results 22 | snapshot: 5000 23 | snapshot_prefix: "examples/cifar10/cifar10_quick" 24 | # solver mode: CPU or GPU 25 | solver_mode: GPU 26 | -------------------------------------------------------------------------------- /caffe-wsl/examples/cifar10/create_cifar10.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # This script converts the cifar data into leveldb format. 3 | 4 | EXAMPLE=examples/cifar10 5 | DATA=data/cifar10 6 | DBTYPE=lmdb 7 | 8 | echo "Creating $DBTYPE..." 9 | 10 | rm -rf $EXAMPLE/cifar10_train_$DBTYPE $EXAMPLE/cifar10_test_$DBTYPE 11 | 12 | ./build/examples/cifar10/convert_cifar_data.bin $DATA $EXAMPLE $DBTYPE 13 | 14 | echo "Computing image mean..." 15 | 16 | ./build/tools/compute_image_mean -backend=$DBTYPE \ 17 | $EXAMPLE/cifar10_train_$DBTYPE $EXAMPLE/mean.binaryproto 18 | 19 | echo "Done." 20 | -------------------------------------------------------------------------------- /caffe-wsl/examples/cifar10/train_full.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | TOOLS=./build/tools 4 | 5 | $TOOLS/caffe train \ 6 | --solver=examples/cifar10/cifar10_full_solver.prototxt 7 | 8 | # reduce learning rate by factor of 10 9 | $TOOLS/caffe train \ 10 | --solver=examples/cifar10/cifar10_full_solver_lr1.prototxt \ 11 | --snapshot=examples/cifar10/cifar10_full_iter_60000.solverstate 12 | 13 | # reduce learning rate by factor of 10 14 | $TOOLS/caffe train \ 15 | --solver=examples/cifar10/cifar10_full_solver_lr2.prototxt \ 16 | --snapshot=examples/cifar10/cifar10_full_iter_65000.solverstate 17 | -------------------------------------------------------------------------------- /caffe-wsl/examples/cifar10/train_quick.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | TOOLS=./build/tools 4 | 5 | $TOOLS/caffe train \ 6 | --solver=examples/cifar10/cifar10_quick_solver.prototxt 7 | 8 | # reduce learning rate by factor of 10 after 8 epochs 9 | $TOOLS/caffe train \ 10 | --solver=examples/cifar10/cifar10_quick_solver_lr1.prototxt \ 11 | --snapshot=examples/cifar10/cifar10_quick_iter_4000.solverstate 12 | -------------------------------------------------------------------------------- /caffe-wsl/examples/finetune_flickr_style/flickr_style.csv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/examples/finetune_flickr_style/flickr_style.csv.gz -------------------------------------------------------------------------------- /caffe-wsl/examples/finetune_flickr_style/style_names.txt: -------------------------------------------------------------------------------- 1 | Detailed 2 | Pastel 3 | Melancholy 4 | Noir 5 | HDR 6 | Vintage 7 | Long Exposure 8 | Horror 9 | Sunny 10 | Bright 11 | Hazy 12 | Bokeh 13 | Serene 14 | Texture 15 | Ethereal 16 | Macro 17 | Depth of Field 18 | Geometric Composition 19 | Minimal 20 | Romantic 21 | -------------------------------------------------------------------------------- /caffe-wsl/examples/finetune_pascal_detection/pascal_finetune_solver.prototxt: -------------------------------------------------------------------------------- 1 | net: "examples/finetune_pascal_detection/pascal_finetune_trainval_test.prototxt" 2 | test_iter: 100 3 | test_interval: 1000 4 | base_lr: 0.001 5 | lr_policy: "step" 6 | gamma: 0.1 7 | stepsize: 20000 8 | display: 20 9 | max_iter: 100000 10 | momentum: 0.9 11 | weight_decay: 0.0005 12 | snapshot: 10000 13 | snapshot_prefix: "examples/finetune_pascal_detection/pascal_det_finetune" 14 | -------------------------------------------------------------------------------- /caffe-wsl/examples/hdf5_classification/solver.prototxt: -------------------------------------------------------------------------------- 1 | net: "hdf5_classification/train_val.prototxt" 2 | test_iter: 250 3 | test_interval: 1000 4 | base_lr: 0.01 5 | lr_policy: "step" 6 | gamma: 0.1 7 | stepsize: 5000 8 | display: 1000 9 | max_iter: 10000 10 | momentum: 0.9 11 | weight_decay: 0.0005 12 | snapshot: 10000 13 | snapshot_prefix: "hdf5_classification/data/train" 14 | solver_mode: CPU 15 | -------------------------------------------------------------------------------- /caffe-wsl/examples/hdf5_classification/solver2.prototxt: -------------------------------------------------------------------------------- 1 | net: "hdf5_classification/train_val2.prototxt" 2 | test_iter: 250 3 | test_interval: 1000 4 | base_lr: 0.01 5 | lr_policy: "step" 6 | gamma: 0.1 7 | stepsize: 5000 8 | display: 1000 9 | max_iter: 10000 10 | momentum: 0.9 11 | weight_decay: 0.0005 12 | snapshot: 10000 13 | snapshot_prefix: "hdf5_classification/data/train" 14 | solver_mode: CPU 15 | -------------------------------------------------------------------------------- /caffe-wsl/examples/hdf5_classification/train_val.prototxt: -------------------------------------------------------------------------------- 1 | name: "LogisticRegressionNet" 2 | layer { 3 | name: "data" 4 | type: "HDF5Data" 5 | top: "data" 6 | top: "label" 7 | include { 8 | phase: TRAIN 9 | } 10 | hdf5_data_param { 11 | source: "hdf5_classification/data/train.txt" 12 | batch_size: 10 13 | } 14 | } 15 | layer { 16 | name: "data" 17 | type: "HDF5Data" 18 | top: "data" 19 | top: "label" 20 | include { 21 | phase: TEST 22 | } 23 | hdf5_data_param { 24 | source: "hdf5_classification/data/test.txt" 25 | batch_size: 10 26 | } 27 | } 28 | layer { 29 | name: "fc1" 30 | type: "InnerProduct" 31 | bottom: "data" 32 | top: "fc1" 33 | param { 34 | lr_mult: 1 35 | decay_mult: 1 36 | } 37 | param { 38 | lr_mult: 2 39 | decay_mult: 0 40 | } 41 | inner_product_param { 42 | num_output: 2 43 | weight_filler { 44 | type: "gaussian" 45 | std: 0.01 46 | } 47 | bias_filler { 48 | type: "constant" 49 | value: 0 50 | } 51 | } 52 | } 53 | layer { 54 | name: "loss" 55 | type: "SoftmaxWithLoss" 56 | bottom: "fc1" 57 | bottom: "label" 58 | top: "loss" 59 | } 60 | layer { 61 | name: "accuracy" 62 | type: "Accuracy" 63 | bottom: "fc1" 64 | bottom: "label" 65 | top: "accuracy" 66 | include { 67 | phase: TEST 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /caffe-wsl/examples/imagenet/make_imagenet_mean.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # Compute the mean image from the imagenet training lmdb 3 | # N.B. this is available in data/ilsvrc12 4 | 5 | EXAMPLE=examples/imagenet 6 | DATA=data/ilsvrc12 7 | TOOLS=build/tools 8 | 9 | $TOOLS/compute_image_mean $EXAMPLE/ilsvrc12_train_lmdb \ 10 | $DATA/imagenet_mean.binaryproto 11 | 12 | echo "Done." 13 | -------------------------------------------------------------------------------- /caffe-wsl/examples/imagenet/resume_training.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ./build/tools/caffe train \ 4 | --solver=models/bvlc_reference_caffenet/solver.prototxt \ 5 | --snapshot=models/bvlc_reference_caffenet/caffenet_train_10000.solverstate 6 | -------------------------------------------------------------------------------- /caffe-wsl/examples/imagenet/train_caffenet.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ./build/tools/caffe train \ 4 | --solver=models/bvlc_reference_caffenet/solver.prototxt 5 | -------------------------------------------------------------------------------- /caffe-wsl/examples/images/cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/examples/images/cat.jpg -------------------------------------------------------------------------------- /caffe-wsl/examples/images/cat_gray.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/examples/images/cat_gray.jpg -------------------------------------------------------------------------------- /caffe-wsl/examples/images/fish-bike.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/examples/images/fish-bike.jpg -------------------------------------------------------------------------------- /caffe-wsl/examples/mnist/create_mnist.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # This script converts the mnist data into lmdb/leveldb format, 3 | # depending on the value assigned to $BACKEND. 4 | 5 | EXAMPLE=examples/mnist 6 | DATA=data/mnist 7 | BUILD=build/examples/mnist 8 | 9 | BACKEND="lmdb" 10 | 11 | echo "Creating ${BACKEND}..." 12 | 13 | rm -rf $EXAMPLE/mnist_train_${BACKEND} 14 | rm -rf $EXAMPLE/mnist_test_${BACKEND} 15 | 16 | $BUILD/convert_mnist_data.bin $DATA/train-images-idx3-ubyte \ 17 | $DATA/train-labels-idx1-ubyte $EXAMPLE/mnist_train_${BACKEND} --backend=${BACKEND} 18 | $BUILD/convert_mnist_data.bin $DATA/t10k-images-idx3-ubyte \ 19 | $DATA/t10k-labels-idx1-ubyte $EXAMPLE/mnist_test_${BACKEND} --backend=${BACKEND} 20 | 21 | echo "Done." 22 | -------------------------------------------------------------------------------- /caffe-wsl/examples/mnist/lenet_multistep_solver.prototxt: -------------------------------------------------------------------------------- 1 | # The train/test net protocol buffer definition 2 | net: "examples/mnist/lenet_train_test.prototxt" 3 | # test_iter specifies how many forward passes the test should carry out. 4 | # In the case of MNIST, we have test batch size 100 and 100 test iterations, 5 | # covering the full 10,000 testing images. 6 | test_iter: 100 7 | # Carry out testing every 500 training iterations. 8 | test_interval: 500 9 | # The base learning rate, momentum and the weight decay of the network. 10 | base_lr: 0.01 11 | momentum: 0.9 12 | weight_decay: 0.0005 13 | # The learning rate policy 14 | lr_policy: "multistep" 15 | gamma: 0.9 16 | stepvalue: 5000 17 | stepvalue: 7000 18 | stepvalue: 8000 19 | stepvalue: 9000 20 | stepvalue: 9500 21 | # Display every 100 iterations 22 | display: 100 23 | # The maximum number of iterations 24 | max_iter: 10000 25 | # snapshot intermediate results 26 | snapshot: 5000 27 | snapshot_prefix: "examples/mnist/lenet_multistep" 28 | # solver mode: CPU or GPU 29 | solver_mode: GPU 30 | -------------------------------------------------------------------------------- /caffe-wsl/examples/mnist/lenet_solver.prototxt: -------------------------------------------------------------------------------- 1 | # The train/test net protocol buffer definition 2 | net: "examples/mnist/lenet_train_test.prototxt" 3 | # test_iter specifies how many forward passes the test should carry out. 4 | # In the case of MNIST, we have test batch size 100 and 100 test iterations, 5 | # covering the full 10,000 testing images. 6 | test_iter: 100 7 | # Carry out testing every 500 training iterations. 8 | test_interval: 500 9 | # The base learning rate, momentum and the weight decay of the network. 10 | base_lr: 0.01 11 | momentum: 0.9 12 | weight_decay: 0.0005 13 | # The learning rate policy 14 | lr_policy: "inv" 15 | gamma: 0.0001 16 | power: 0.75 17 | # Display every 100 iterations 18 | display: 100 19 | # The maximum number of iterations 20 | max_iter: 10000 21 | # snapshot intermediate results 22 | snapshot: 5000 23 | snapshot_prefix: "examples/mnist/lenet" 24 | # solver mode: CPU or GPU 25 | solver_mode: GPU 26 | -------------------------------------------------------------------------------- /caffe-wsl/examples/mnist/lenet_stepearly_solver.prototxt: -------------------------------------------------------------------------------- 1 | # The training protocol buffer definition 2 | train_net: "lenet_train.prototxt" 3 | # The testing protocol buffer definition 4 | test_net: "lenet_test.prototxt" 5 | # test_iter specifies how many forward passes the test should carry out. 6 | # In the case of MNIST, we have test batch size 100 and 100 test iterations, 7 | # covering the full 10,000 testing images. 8 | test_iter: 100 9 | # Carry out testing every 500 training iterations. 10 | test_interval: 500 11 | # The base learning rate, momentum and the weight decay of the network. 12 | base_lr: 0.01 13 | momentum: 0.9 14 | weight_decay: 0.0005 15 | # The learning rate policy 16 | lr_policy: "stepearly" 17 | gamma: 0.9 18 | stepearly: 1 19 | # Display every 100 iterations 20 | display: 100 21 | # The maximum number of iterations 22 | max_iter: 10000 23 | # snapshot intermediate results 24 | snapshot: 5000 25 | snapshot_prefix: "lenet" 26 | # solver mode: 0 for CPU and 1 for GPU 27 | solver_mode: 1 28 | device_id: 1 29 | -------------------------------------------------------------------------------- /caffe-wsl/examples/mnist/mnist_autoencoder_solver.prototxt: -------------------------------------------------------------------------------- 1 | net: "examples/mnist/mnist_autoencoder.prototxt" 2 | test_state: { stage: 'test-on-train' } 3 | test_iter: 500 4 | test_state: { stage: 'test-on-test' } 5 | test_iter: 100 6 | test_interval: 500 7 | test_compute_loss: true 8 | base_lr: 0.01 9 | lr_policy: "step" 10 | gamma: 0.1 11 | stepsize: 10000 12 | display: 100 13 | max_iter: 65000 14 | weight_decay: 0.0005 15 | snapshot: 10000 16 | snapshot_prefix: "examples/mnist/mnist_autoencoder" 17 | momentum: 0.9 18 | # solver mode: CPU or GPU 19 | solver_mode: GPU 20 | -------------------------------------------------------------------------------- /caffe-wsl/examples/mnist/mnist_autoencoder_solver_adagrad.prototxt: -------------------------------------------------------------------------------- 1 | net: "examples/mnist/mnist_autoencoder.prototxt" 2 | test_state: { stage: 'test-on-train' } 3 | test_iter: 500 4 | test_state: { stage: 'test-on-test' } 5 | test_iter: 100 6 | test_interval: 500 7 | test_compute_loss: true 8 | base_lr: 0.01 9 | lr_policy: "fixed" 10 | display: 100 11 | max_iter: 65000 12 | weight_decay: 0.0005 13 | snapshot: 10000 14 | snapshot_prefix: "examples/mnist/mnist_autoencoder_adagrad_train" 15 | # solver mode: CPU or GPU 16 | solver_mode: GPU 17 | solver_type: ADAGRAD 18 | -------------------------------------------------------------------------------- /caffe-wsl/examples/mnist/mnist_autoencoder_solver_nesterov.prototxt: -------------------------------------------------------------------------------- 1 | net: "examples/mnist/mnist_autoencoder.prototxt" 2 | test_state: { stage: 'test-on-train' } 3 | test_iter: 500 4 | test_state: { stage: 'test-on-test' } 5 | test_iter: 100 6 | test_interval: 500 7 | test_compute_loss: true 8 | base_lr: 0.01 9 | lr_policy: "step" 10 | gamma: 0.1 11 | stepsize: 10000 12 | display: 100 13 | max_iter: 65000 14 | weight_decay: 0.0005 15 | snapshot: 10000 16 | snapshot_prefix: "examples/mnist/mnist_autoencoder_nesterov_train" 17 | momentum: 0.95 18 | # solver mode: CPU or GPU 19 | solver_mode: GPU 20 | solver_type: NESTEROV 21 | -------------------------------------------------------------------------------- /caffe-wsl/examples/mnist/train_lenet.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ./build/tools/caffe train --solver=examples/mnist/lenet_solver.prototxt 4 | -------------------------------------------------------------------------------- /caffe-wsl/examples/mnist/train_lenet_consolidated.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ./build/tools/caffe train \ 4 | --solver=examples/mnist/lenet_consolidated_solver.prototxt 5 | -------------------------------------------------------------------------------- /caffe-wsl/examples/mnist/train_mnist_autoencoder.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ./build/tools/caffe train \ 4 | --solver=examples/mnist/mnist_autoencoder_solver.prototxt 5 | -------------------------------------------------------------------------------- /caffe-wsl/examples/mnist/train_mnist_autoencoder_adagrad.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./build/tools/caffe train \ 4 | --solver=examples/mnist/mnist_autoencoder_solver_adagrad.prototxt 5 | -------------------------------------------------------------------------------- /caffe-wsl/examples/mnist/train_mnist_autoencoder_nesterov.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./build/tools/caffe train \ 4 | --solver=examples/mnist/mnist_autoencoder_solver_nesterov.prototxt 5 | -------------------------------------------------------------------------------- /caffe-wsl/examples/net_surgery/conv.prototxt: -------------------------------------------------------------------------------- 1 | # Simple single-layer network to showcase editing model parameters. 2 | name: "convolution" 3 | input: "data" 4 | input_dim: 1 5 | input_dim: 1 6 | input_dim: 100 7 | input_dim: 100 8 | layer { 9 | name: "conv" 10 | type: "Convolution" 11 | bottom: "data" 12 | top: "conv" 13 | convolution_param { 14 | num_output: 3 15 | kernel_size: 5 16 | stride: 1 17 | weight_filler { 18 | type: "gaussian" 19 | std: 0.01 20 | } 21 | bias_filler { 22 | type: "constant" 23 | value: 0 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /caffe-wsl/examples/siamese/create_mnist_siamese.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # This script converts the mnist data into leveldb format. 3 | 4 | EXAMPLES=./build/examples/siamese 5 | DATA=./data/mnist 6 | 7 | echo "Creating leveldb..." 8 | 9 | rm -rf ./examples/siamese/mnist_siamese_train_leveldb 10 | rm -rf ./examples/siamese/mnist_siamese_test_leveldb 11 | 12 | $EXAMPLES/convert_mnist_siamese_data.bin \ 13 | $DATA/train-images-idx3-ubyte \ 14 | $DATA/train-labels-idx1-ubyte \ 15 | ./examples/siamese/mnist_siamese_train_leveldb 16 | $EXAMPLES/convert_mnist_siamese_data.bin \ 17 | $DATA/t10k-images-idx3-ubyte \ 18 | $DATA/t10k-labels-idx1-ubyte \ 19 | ./examples/siamese/mnist_siamese_test_leveldb 20 | 21 | echo "Done." 22 | -------------------------------------------------------------------------------- /caffe-wsl/examples/siamese/mnist_siamese_solver.prototxt: -------------------------------------------------------------------------------- 1 | # The train/test net protocol buffer definition 2 | net: "examples/siamese/mnist_siamese_train_test.prototxt" 3 | # test_iter specifies how many forward passes the test should carry out. 4 | # In the case of MNIST, we have test batch size 100 and 100 test iterations, 5 | # covering the full 10,000 testing images. 6 | test_iter: 100 7 | # Carry out testing every 500 training iterations. 8 | test_interval: 500 9 | # The base learning rate, momentum and the weight decay of the network. 10 | base_lr: 0.01 11 | momentum: 0.9 12 | weight_decay: 0.0000 13 | # The learning rate policy 14 | lr_policy: "inv" 15 | gamma: 0.0001 16 | power: 0.75 17 | # Display every 100 iterations 18 | display: 100 19 | # The maximum number of iterations 20 | max_iter: 50000 21 | # snapshot intermediate results 22 | snapshot: 5000 23 | snapshot_prefix: "examples/siamese/mnist_siamese" 24 | # solver mode: CPU or GPU 25 | solver_mode: GPU 26 | -------------------------------------------------------------------------------- /caffe-wsl/examples/siamese/train_mnist_siamese.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | TOOLS=./build/tools 4 | 5 | $TOOLS/caffe train --solver=examples/siamese/mnist_siamese_solver.prototxt 6 | -------------------------------------------------------------------------------- /caffe-wsl/examples/web_demo/exifutil.py: -------------------------------------------------------------------------------- 1 | """ 2 | This script handles the skimage exif problem. 3 | """ 4 | 5 | from PIL import Image 6 | import numpy as np 7 | 8 | ORIENTATIONS = { # used in apply_orientation 9 | 2: (Image.FLIP_LEFT_RIGHT,), 10 | 3: (Image.ROTATE_180,), 11 | 4: (Image.FLIP_TOP_BOTTOM,), 12 | 5: (Image.FLIP_LEFT_RIGHT, Image.ROTATE_90), 13 | 6: (Image.ROTATE_270,), 14 | 7: (Image.FLIP_LEFT_RIGHT, Image.ROTATE_270), 15 | 8: (Image.ROTATE_90,) 16 | } 17 | 18 | 19 | def open_oriented_im(im_path): 20 | im = Image.open(im_path) 21 | if hasattr(im, '_getexif'): 22 | exif = im._getexif() 23 | if exif is not None and 274 in exif: 24 | orientation = exif[274] 25 | im = apply_orientation(im, orientation) 26 | img = np.asarray(im).astype(np.float32) / 255. 27 | if img.ndim == 2: 28 | img = img[:, :, np.newaxis] 29 | img = np.tile(img, (1, 1, 3)) 30 | elif img.shape[2] == 4: 31 | img = img[:, :, :3] 32 | return img 33 | 34 | 35 | def apply_orientation(im, orientation): 36 | if orientation in ORIENTATIONS: 37 | for method in ORIENTATIONS[orientation]: 38 | im = im.transpose(method) 39 | return im 40 | -------------------------------------------------------------------------------- /caffe-wsl/examples/web_demo/requirements.txt: -------------------------------------------------------------------------------- 1 | werkzeug 2 | flask 3 | tornado 4 | numpy 5 | pandas 6 | pillow 7 | -------------------------------------------------------------------------------- /caffe-wsl/include/caffe/caffe.hpp: -------------------------------------------------------------------------------- 1 | // caffe.hpp is the header file that you need to include in your code. It wraps 2 | // all the internal caffe header files into one for simpler inclusion. 3 | 4 | #ifndef CAFFE_CAFFE_HPP_ 5 | #define CAFFE_CAFFE_HPP_ 6 | 7 | #include "caffe/blob.hpp" 8 | #include "caffe/common.hpp" 9 | #include "caffe/filler.hpp" 10 | #include "caffe/layer.hpp" 11 | #include "caffe/layer_factory.hpp" 12 | #include "caffe/net.hpp" 13 | #include "caffe/proto/caffe.pb.h" 14 | #include "caffe/solver.hpp" 15 | #include "caffe/util/benchmark.hpp" 16 | #include "caffe/util/io.hpp" 17 | #include "caffe/vision_layers.hpp" 18 | 19 | #endif // CAFFE_CAFFE_HPP_ 20 | -------------------------------------------------------------------------------- /caffe-wsl/include/caffe/internal_thread.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CAFFE_INTERNAL_THREAD_HPP_ 2 | #define CAFFE_INTERNAL_THREAD_HPP_ 3 | 4 | #include "caffe/common.hpp" 5 | 6 | /** 7 | Forward declare boost::thread instead of including boost/thread.hpp 8 | to avoid a boost/NVCC issues (#1009, #1010) on OSX. 9 | */ 10 | namespace boost { class thread; } 11 | 12 | namespace caffe { 13 | 14 | /** 15 | * Virtual class encapsulate boost::thread for use in base class 16 | * The child class will acquire the ability to run a single thread, 17 | * by reimplementing the virutal function InternalThreadEntry. 18 | */ 19 | class InternalThread { 20 | public: 21 | InternalThread() : thread_() {} 22 | virtual ~InternalThread(); 23 | 24 | /** Returns true if the thread was successfully started. **/ 25 | bool StartInternalThread(); 26 | 27 | /** Will not return until the internal thread has exited. */ 28 | bool WaitForInternalThreadToExit(); 29 | 30 | bool is_started() const; 31 | 32 | protected: 33 | /* Implement this method in your subclass 34 | with the code you want your thread to run. */ 35 | virtual void InternalThreadEntry() {} 36 | 37 | shared_ptr thread_; 38 | }; 39 | 40 | } // namespace caffe 41 | 42 | #endif // CAFFE_INTERNAL_THREAD_HPP_ 43 | -------------------------------------------------------------------------------- /caffe-wsl/include/caffe/util/benchmark.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CAFFE_UTIL_BENCHMARK_H_ 2 | #define CAFFE_UTIL_BENCHMARK_H_ 3 | 4 | #include 5 | 6 | #include "caffe/util/device_alternate.hpp" 7 | 8 | namespace caffe { 9 | 10 | class Timer { 11 | public: 12 | Timer(); 13 | virtual ~Timer(); 14 | virtual void Start(); 15 | virtual void Stop(); 16 | virtual float MilliSeconds(); 17 | virtual float MicroSeconds(); 18 | virtual float Seconds(); 19 | 20 | inline bool initted() { return initted_; } 21 | inline bool running() { return running_; } 22 | inline bool has_run_at_least_once() { return has_run_at_least_once_; } 23 | 24 | protected: 25 | void Init(); 26 | 27 | bool initted_; 28 | bool running_; 29 | bool has_run_at_least_once_; 30 | #ifndef CPU_ONLY 31 | cudaEvent_t start_gpu_; 32 | cudaEvent_t stop_gpu_; 33 | #endif 34 | boost::posix_time::ptime start_cpu_; 35 | boost::posix_time::ptime stop_cpu_; 36 | float elapsed_milliseconds_; 37 | float elapsed_microseconds_; 38 | }; 39 | 40 | class CPUTimer : public Timer { 41 | public: 42 | explicit CPUTimer(); 43 | virtual ~CPUTimer() {} 44 | virtual void Start(); 45 | virtual void Stop(); 46 | virtual float MilliSeconds(); 47 | virtual float MicroSeconds(); 48 | }; 49 | 50 | } // namespace caffe 51 | 52 | #endif // CAFFE_UTIL_BENCHMARK_H_ 53 | -------------------------------------------------------------------------------- /caffe-wsl/include/caffe/util/im2col.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _CAFFE_UTIL_IM2COL_HPP_ 2 | #define _CAFFE_UTIL_IM2COL_HPP_ 3 | 4 | namespace caffe { 5 | 6 | template 7 | void im2col_cpu(const Dtype* data_im, const int channels, 8 | const int height, const int width, const int kernel_h, const int kernel_w, 9 | const int pad_h, const int pad_w, const int stride_h, 10 | const int stride_w, Dtype* data_col); 11 | 12 | template 13 | void col2im_cpu(const Dtype* data_col, const int channels, 14 | const int height, const int width, const int patch_h, const int patch_w, 15 | const int pad_h, const int pad_w, const int stride_h, 16 | const int stride_w, Dtype* data_im); 17 | 18 | template 19 | void im2col_gpu(const Dtype* data_im, const int channels, 20 | const int height, const int width, const int kernel_h, const int kernel_w, 21 | const int pad_h, const int pad_w, const int stride_h, 22 | const int stride_w, Dtype* data_col); 23 | 24 | template 25 | void col2im_gpu(const Dtype* data_col, const int channels, 26 | const int height, const int width, const int patch_h, const int patch_w, 27 | const int pad_h, const int pad_w, const int stride_h, 28 | const int stride_w, Dtype* data_im); 29 | 30 | } // namespace caffe 31 | 32 | #endif // CAFFE_UTIL_IM2COL_HPP_ 33 | -------------------------------------------------------------------------------- /caffe-wsl/include/caffe/util/insert_splits.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _CAFFE_UTIL_INSERT_SPLITS_HPP_ 2 | #define _CAFFE_UTIL_INSERT_SPLITS_HPP_ 3 | 4 | #include 5 | 6 | #include "caffe/proto/caffe.pb.h" 7 | 8 | namespace caffe { 9 | 10 | // Copy NetParameters with SplitLayers added to replace any shared bottom 11 | // blobs with unique bottom blobs provided by the SplitLayer. 12 | void InsertSplits(const NetParameter& param, NetParameter* param_split); 13 | 14 | void ConfigureSplitLayer(const string& layer_name, const string& blob_name, 15 | const int blob_idx, const int split_count, const float loss_weight, 16 | LayerParameter* split_layer_param); 17 | 18 | string SplitLayerName(const string& layer_name, const string& blob_name, 19 | const int blob_idx); 20 | 21 | string SplitBlobName(const string& layer_name, const string& blob_name, 22 | const int blob_idx, const int split_idx); 23 | 24 | } // namespace caffe 25 | 26 | #endif // CAFFE_UTIL_INSERT_SPLITS_HPP_ 27 | -------------------------------------------------------------------------------- /caffe-wsl/include/caffe/util/rng.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CAFFE_RNG_CPP_HPP_ 2 | #define CAFFE_RNG_CPP_HPP_ 3 | 4 | #include 5 | #include 6 | 7 | #include "boost/random/mersenne_twister.hpp" 8 | #include "boost/random/uniform_int.hpp" 9 | 10 | #include "caffe/common.hpp" 11 | 12 | namespace caffe { 13 | 14 | typedef boost::mt19937 rng_t; 15 | 16 | inline rng_t* caffe_rng() { 17 | return static_cast(Caffe::rng_stream().generator()); 18 | } 19 | 20 | // Fisher–Yates algorithm 21 | template 22 | inline void shuffle(RandomAccessIterator begin, RandomAccessIterator end, 23 | RandomGenerator* gen) { 24 | typedef typename std::iterator_traits::difference_type 25 | difference_type; 26 | typedef typename boost::uniform_int dist_type; 27 | 28 | difference_type length = std::distance(begin, end); 29 | if (length <= 0) return; 30 | 31 | for (difference_type i = length - 1; i > 0; --i) { 32 | dist_type dist(0, i); 33 | std::iter_swap(begin + i, begin + dist(*gen)); 34 | } 35 | } 36 | 37 | template 38 | inline void shuffle(RandomAccessIterator begin, RandomAccessIterator end) { 39 | shuffle(begin, end, caffe_rng()); 40 | } 41 | } // namespace caffe 42 | 43 | #endif // CAFFE_RNG_HPP_ 44 | -------------------------------------------------------------------------------- /caffe-wsl/matlab/caffe/caffe.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/matlab/caffe/caffe.mexa64 -------------------------------------------------------------------------------- /caffe-wsl/matlab/caffe/ilsvrc_2012_mean.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/matlab/caffe/ilsvrc_2012_mean.mat -------------------------------------------------------------------------------- /caffe-wsl/matlab/caffe/matcaffe_init.m: -------------------------------------------------------------------------------- 1 | function matcaffe_init(use_gpu, model_def_file, model_file) 2 | % matcaffe_init(model_def_file, model_file, use_gpu) 3 | % Initilize matcaffe wrapper 4 | 5 | if nargin < 1 6 | % By default use CPU 7 | use_gpu = 0; 8 | end 9 | if nargin < 2 || isempty(model_def_file) 10 | % By default use imagenet_deploy 11 | model_def_file = '../../models/bvlc_reference_caffenet/deploy.prototxt'; 12 | end 13 | if nargin < 3 || isempty(model_file) 14 | % By default use caffe reference model 15 | model_file = '../../models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel'; 16 | end 17 | 18 | 19 | if caffe('is_initialized') == 0 20 | if exist(model_file, 'file') == 0 21 | % NOTE: you'll have to get the pre-trained ILSVRC network 22 | error('You need a network model file'); 23 | end 24 | if ~exist(model_def_file,'file') 25 | % NOTE: you'll have to get network definition 26 | error('You need the network prototxt definition'); 27 | end 28 | % load network in TEST phase 29 | caffe('init', model_def_file, model_file, 'test') 30 | end 31 | fprintf('Done with init\n'); 32 | 33 | % set to use GPU or CPU 34 | if use_gpu 35 | fprintf('Using GPU Mode\n'); 36 | caffe('set_mode_gpu'); 37 | else 38 | fprintf('Using CPU Mode\n'); 39 | caffe('set_mode_cpu'); 40 | end 41 | fprintf('Done with set_mode\n'); 42 | -------------------------------------------------------------------------------- /caffe-wsl/matlab/caffe/prepare_batch.m: -------------------------------------------------------------------------------- 1 | % ------------------------------------------------------------------------ 2 | function images = prepare_batch(image_files,IMAGE_MEAN,batch_size) 3 | % ------------------------------------------------------------------------ 4 | if nargin < 2 5 | d = load('ilsvrc_2012_mean'); 6 | IMAGE_MEAN = d.image_mean; 7 | end 8 | num_images = length(image_files); 9 | if nargin < 3 10 | batch_size = num_images; 11 | end 12 | 13 | IMAGE_DIM = 256; 14 | CROPPED_DIM = 227; 15 | indices = [0 IMAGE_DIM-CROPPED_DIM] + 1; 16 | center = floor(indices(2) / 2)+1; 17 | 18 | num_images = length(image_files); 19 | images = zeros(CROPPED_DIM,CROPPED_DIM,3,batch_size,'single'); 20 | 21 | parfor i=1:num_images 22 | % read file 23 | fprintf('%c Preparing %s\n',13,image_files{i}); 24 | try 25 | im = imread(image_files{i}); 26 | % resize to fixed input size 27 | im = single(im); 28 | im = imresize(im, [IMAGE_DIM IMAGE_DIM], 'bilinear'); 29 | % Transform GRAY to RGB 30 | if size(im,3) == 1 31 | im = cat(3,im,im,im); 32 | end 33 | % permute from RGB to BGR (IMAGE_MEAN is already BGR) 34 | im = im(:,:,[3 2 1]) - IMAGE_MEAN; 35 | % Crop the center of the image 36 | images(:,:,:,i) = permute(im(center:center+CROPPED_DIM-1,... 37 | center:center+CROPPED_DIM-1,:),[2 1 3]); 38 | catch 39 | warning('Problems with file',image_files{i}); 40 | end 41 | end -------------------------------------------------------------------------------- /caffe-wsl/matlab/caffe/print_cell.m: -------------------------------------------------------------------------------- 1 | function res=print_cell(input,file,linesep,cellsep) 2 | assert(iscell(input),'The input should be a cell') 3 | if nargin < 4 4 | cellsep = '\t'; 5 | end 6 | if nargin < 3 7 | linesep = '\n'; 8 | end 9 | if exist('file','var') && ~isempty(file) 10 | %% 11 | fid = fopen(file,'w'); 12 | for l=1:length(input) 13 | if iscell(input{l}) 14 | for i=1:length(input{l}) 15 | fprintf(fid,['%s' cellsep],input{l}{i}); 16 | end 17 | fprintf(fid,linesep); 18 | else 19 | if size(input,2) > 1 20 | for i=1:size(input,2) 21 | fprintf(fid,'%s ',input{l,i}); 22 | end 23 | fprintf(fid,linesep); 24 | else 25 | fprintf(fid,['%s' linesep],input{l}); 26 | end 27 | end 28 | end 29 | fclose(fid); 30 | else 31 | res = ''; 32 | for l=1:length(input) 33 | if iscell(input{l}) 34 | for i=1:length(input{l}) 35 | res = [res sprintf([cellsep{1} '%s' cellsep{2}],input{l}{i})]; 36 | end 37 | res = [res sprintf(linesep)]; 38 | else 39 | res = [res sprintf(['%s' linesep],input{l}(:))]; 40 | end 41 | end 42 | end -------------------------------------------------------------------------------- /caffe-wsl/matlab/caffe/read_cell.m: -------------------------------------------------------------------------------- 1 | function res=read_cell(filename,linesep,cellsep) 2 | if nargin < 2, linesep='\n'; end 3 | if nargin < 3, cellsep = '\t'; end 4 | if exist(filename,'file') 5 | fid = fopen(filename); 6 | else 7 | % Assume that filename is either a file ide or a string 8 | fid = filename; 9 | end 10 | 11 | fileLines = textscan(fid,'%s','delimiter',linesep,'BufSize',100000); 12 | 13 | fileLines = fileLines{1}; 14 | 15 | if regexp(fileLines{1},cellsep,'once') 16 | fileLines = regexprep(fileLines,['^' cellsep '|' cellsep '$'],''); 17 | res = regexp(fileLines,cellsep,'split'); 18 | res = cell2matcell(res); 19 | else 20 | res = fileLines; 21 | end 22 | -------------------------------------------------------------------------------- /caffe-wsl/models/bvlc_alexnet/readme.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: BVLC AlexNet Model 3 | caffemodel: bvlc_alexnet.caffemodel 4 | caffemodel_url: http://dl.caffe.berkeleyvision.org/bvlc_alexnet.caffemodel 5 | license: unrestricted 6 | sha1: 9116a64c0fbe4459d18f4bb6b56d647b63920377 7 | caffe_commit: 709dc15af4a06bebda027c1eb2b3f3e3375d5077 8 | --- 9 | 10 | This model is a replication of the model described in the [AlexNet](http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks) publication. 11 | 12 | Differences: 13 | - not training with the relighting data-augmentation; 14 | - initializing non-zero biases to 0.1 instead of 1 (found necessary for training, as initialization to 1 gave flat loss). 15 | 16 | The bundled model is the iteration 360,000 snapshot. 17 | The best validation performance during training was iteration 358,000 with validation accuracy 57.258% and loss 1.83948. 18 | This model obtains a top-1 accuracy 57.1% and a top-5 accuracy 80.2% on the validation set, using just the center crop. 19 | (Using the average of 10 crops, (4 + 1 center) * 2 mirror, should obtain a bit higher accuracy.) 20 | 21 | This model was trained by Evan Shelhamer @shelhamer 22 | 23 | ## License 24 | 25 | This model is released for unrestricted use. 26 | -------------------------------------------------------------------------------- /caffe-wsl/models/bvlc_alexnet/solver.prototxt: -------------------------------------------------------------------------------- 1 | net: "models/bvlc_alexnet/train_val.prototxt" 2 | test_iter: 1000 3 | test_interval: 1000 4 | base_lr: 0.01 5 | lr_policy: "step" 6 | gamma: 0.1 7 | stepsize: 100000 8 | display: 20 9 | max_iter: 450000 10 | momentum: 0.9 11 | weight_decay: 0.0005 12 | snapshot: 10000 13 | snapshot_prefix: "models/bvlc_alexnet/caffe_alexnet_train" 14 | solver_mode: GPU 15 | -------------------------------------------------------------------------------- /caffe-wsl/models/bvlc_googlenet/quick_solver.prototxt: -------------------------------------------------------------------------------- 1 | net: "models/bvlc_googlenet/train_val.prototxt" 2 | test_iter: 1000 3 | test_interval: 4000 4 | test_initialization: false 5 | display: 40 6 | average_loss: 40 7 | base_lr: 0.01 8 | lr_policy: "poly" 9 | power: 0.5 10 | max_iter: 2400000 11 | momentum: 0.9 12 | weight_decay: 0.0002 13 | snapshot: 40000 14 | snapshot_prefix: "models/bvlc_googlenet/bvlc_googlenet_quick" 15 | solver_mode: GPU 16 | -------------------------------------------------------------------------------- /caffe-wsl/models/bvlc_googlenet/readme.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: BVLC GoogleNet Model 3 | caffemodel: bvlc_googlenet.caffemodel 4 | caffemodel_url: http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel 5 | license: unrestricted 6 | sha1: 405fc5acd08a3bb12de8ee5e23a96bec22f08204 7 | caffe_commit: bc614d1bd91896e3faceaf40b23b72dab47d44f5 8 | --- 9 | 10 | This model is a replication of the model described in the [GoogleNet](http://arxiv.org/abs/1409.4842) publication. We would like to thank Christian Szegedy for all his help in the replication of GoogleNet model. 11 | 12 | Differences: 13 | - not training with the relighting data-augmentation; 14 | - not training with the scale or aspect-ratio data-augmentation; 15 | - uses "xavier" to initialize the weights instead of "gaussian"; 16 | - quick_solver.prototxt uses a different learning rate decay policy than the original solver.prototxt, that allows a much faster training (60 epochs vs 250 epochs); 17 | 18 | The bundled model is the iteration 2,400,000 snapshot (60 epochs) using quick_solver.prototxt 19 | 20 | This bundled model obtains a top-1 accuracy 68.7% (31.3% error) and a top-5 accuracy 88.9% (11.1% error) on the validation set, using just the center crop. 21 | (Using the average of 10 crops, (4 + 1 center) * 2 mirror, should obtain a bit higher accuracy.) 22 | 23 | Timings for bvlc_googlenet with cuDNN using batch_size:128 on a K40c: 24 | - Average Forward pass: 562.841 ms. 25 | - Average Backward pass: 1123.84 ms. 26 | - Average Forward-Backward: 1688.8 ms. 27 | 28 | This model was trained by Sergio Guadarrama @sguada 29 | 30 | ## License 31 | 32 | This model is released for unrestricted use. 33 | -------------------------------------------------------------------------------- /caffe-wsl/models/bvlc_googlenet/solver.prototxt: -------------------------------------------------------------------------------- 1 | net: "models/bvlc_googlenet/train_val.prototxt" 2 | test_iter: 1000 3 | test_interval: 4000 4 | test_initialization: false 5 | display: 40 6 | average_loss: 40 7 | base_lr: 0.01 8 | lr_policy: "step" 9 | stepsize: 320000 10 | gamma: 0.96 11 | max_iter: 10000000 12 | momentum: 0.9 13 | weight_decay: 0.0002 14 | snapshot: 40000 15 | snapshot_prefix: "models/bvlc_googlenet/bvlc_googlenet" 16 | solver_mode: GPU 17 | -------------------------------------------------------------------------------- /caffe-wsl/models/bvlc_reference_caffenet/readme.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: BVLC CaffeNet Model 3 | caffemodel: bvlc_reference_caffenet.caffemodel 4 | caffemodel_url: http://dl.caffe.berkeleyvision.org/bvlc_reference_caffenet.caffemodel 5 | license: unrestricted 6 | sha1: 4c8d77deb20ea792f84eb5e6d0a11ca0a8660a46 7 | caffe_commit: 709dc15af4a06bebda027c1eb2b3f3e3375d5077 8 | --- 9 | 10 | This model is the result of following the Caffe [ImageNet model training instructions](http://caffe.berkeleyvision.org/gathered/examples/imagenet.html). 11 | It is a replication of the model described in the [AlexNet](http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks) publication with some differences: 12 | 13 | - not training with the relighting data-augmentation; 14 | - the order of pooling and normalization layers is switched (in CaffeNet, pooling is done before normalization). 15 | 16 | This model is snapshot of iteration 310,000. 17 | The best validation performance during training was iteration 313,000 with validation accuracy 57.412% and loss 1.82328. 18 | This model obtains a top-1 accuracy 57.4% and a top-5 accuracy 80.4% on the validation set, using just the center crop. 19 | (Using the average of 10 crops, (4 + 1 center) * 2 mirror, should obtain a bit higher accuracy still.) 20 | 21 | This model was trained by Jeff Donahue @jeffdonahue 22 | 23 | ## License 24 | 25 | This model is released for unrestricted use. 26 | -------------------------------------------------------------------------------- /caffe-wsl/models/bvlc_reference_caffenet/solver.prototxt: -------------------------------------------------------------------------------- 1 | net: "models/bvlc_reference_caffenet/train_val.prototxt" 2 | test_iter: 1000 3 | test_interval: 1000 4 | base_lr: 0.01 5 | lr_policy: "step" 6 | gamma: 0.1 7 | stepsize: 100000 8 | display: 20 9 | max_iter: 450000 10 | momentum: 0.9 11 | weight_decay: 0.0005 12 | snapshot: 10000 13 | snapshot_prefix: "models/bvlc_reference_caffenet/caffenet_train" 14 | solver_mode: GPU 15 | -------------------------------------------------------------------------------- /caffe-wsl/models/bvlc_reference_rcnn_ilsvrc13/readme.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: BVLC Reference RCNN ILSVRC13 Model 3 | caffemodel: bvlc_reference_rcnn_ilsvrc13.caffemodel 4 | caffemodel_url: http://dl.caffe.berkeleyvision.org/bvlc_reference_rcnn_ilsvrc13.caffemodel 5 | license: unrestricted 6 | sha1: bdd8abb885819cba5e2fe1eb36235f2319477e64 7 | caffe_commit: a7e397abbda52c0b90323c23ab95bdeabee90a98 8 | --- 9 | 10 | The pure Caffe instantiation of the [R-CNN](https://github.com/rbgirshick/rcnn) model for ILSVRC13 detection. 11 | This model was made by transplanting the R-CNN SVM classifiers into a `fc-rcnn` classification layer, provided here as an off-the-shelf Caffe detector. 12 | Try the [detection example](http://nbviewer.ipython.org/github/BVLC/caffe/blob/master/examples/detection.ipynb) to see it in action. 13 | 14 | *N.B. For research purposes, make use of the official R-CNN package and not this example.* 15 | 16 | This model was trained by Ross Girshick @rbgirshick 17 | 18 | ## License 19 | 20 | This model is released for unrestricted use. 21 | -------------------------------------------------------------------------------- /caffe-wsl/models/finetune_flickr_style/readme.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Finetuning CaffeNet on Flickr Style 3 | caffemodel: finetune_flickr_style.caffemodel 4 | caffemodel_url: http://dl.caffe.berkeleyvision.org/finetune_flickr_style.caffemodel 5 | license: non-commercial 6 | sha1: b61b5cef7d771b53b0c488e78d35ccadc073e9cf 7 | caffe_commit: 737ea5e936821b5c69f9c3952d72693ae5843370 8 | gist_id: 034c6ac3865563b69e60 9 | --- 10 | 11 | This model is trained exactly as described in `docs/finetune_flickr_style/readme.md`, using all 80000 images. 12 | The final performance: 13 | 14 | I1017 07:36:17.370688 31333 solver.cpp:228] Iteration 100000, loss = 0.757952 15 | I1017 07:36:17.370730 31333 solver.cpp:247] Iteration 100000, Testing net (#0) 16 | I1017 07:36:34.248730 31333 solver.cpp:298] Test net output #0: accuracy = 0.3916 17 | 18 | This model was trained by Sergey Karayev @sergeyk 19 | 20 | ## License 21 | 22 | The Flickr Style dataset contains only URLs to images. 23 | Some of the images may have copyright. 24 | Training a category-recognition model for research/non-commercial use may constitute fair use of this data, but the result should not be used for commercial purposes. 25 | -------------------------------------------------------------------------------- /caffe-wsl/models/finetune_flickr_style/solver.prototxt: -------------------------------------------------------------------------------- 1 | net: "models/finetune_flickr_style/train_val.prototxt" 2 | test_iter: 100 3 | test_interval: 1000 4 | # lr for fine-tuning should be lower than when starting from scratch 5 | base_lr: 0.001 6 | lr_policy: "step" 7 | gamma: 0.1 8 | # stepsize should also be lower, as we're closer to being done 9 | stepsize: 20000 10 | display: 20 11 | max_iter: 100000 12 | momentum: 0.9 13 | weight_decay: 0.0005 14 | snapshot: 10000 15 | snapshot_prefix: "models/finetune_flickr_style/finetune_flickr_style" 16 | # uncomment the following to default to CPU mode solving 17 | # solver_mode: CPU 18 | -------------------------------------------------------------------------------- /caffe-wsl/python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(NOT HAVE_PYTHON) 2 | message(STATUS "Python interface is disabled or not all required dependecies found. Building without it...") 3 | return() 4 | endif() 5 | 6 | include_directories(${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR} ${Boost_INCLUDE_DIRS}) 7 | file(GLOB_RECURSE python_srcs ${PROJECT_SOURCE_DIR}/python/*.cpp) 8 | 9 | add_library(pycaffe SHARED ${python_srcs}) 10 | target_link_libraries(pycaffe ${Caffe_LINK} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES}) 11 | set_target_properties(pycaffe PROPERTIES PREFIX "" OUTPUT_NAME "_caffe") 12 | caffe_default_properties(pycaffe) 13 | 14 | if(UNIX OR APPLE) 15 | set(__linkname "${PROJECT_SOURCE_DIR}/python/caffe/_caffe.so") 16 | add_custom_command(TARGET pycaffe POST_BUILD 17 | COMMAND ln -sf $ "${__linkname}" 18 | COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/python/caffe/proto 19 | COMMAND touch ${PROJECT_SOURCE_DIR}/python/caffe/proto/__init__.py 20 | COMMAND cp ${proto_gen_folder}/*.py ${PROJECT_SOURCE_DIR}/python/caffe/proto/ 21 | COMMENT "Creating symlink ${__linkname} -> ${PROJECT_BINARY_DIR}/lib/_caffe${CAffe_POSTFIX}.so") 22 | endif() 23 | 24 | # ---[ Install 25 | file(GLOB files1 *.py requirements.txt) 26 | install(FILES ${files1} DESTINATION python) 27 | 28 | file(GLOB files2 caffe/*.py) 29 | install(FILES ${files2} DESTINATION python/caffe) 30 | install(TARGETS pycaffe DESTINATION python/caffe) 31 | install(DIRECTORY caffe/imagenet caffe/proto caffe/test DESTINATION python/caffe) 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /caffe-wsl/python/caffe/__init__.py: -------------------------------------------------------------------------------- 1 | from .pycaffe import Net, SGDSolver 2 | from ._caffe import set_mode_cpu, set_mode_gpu, set_random_seed, set_device, \ 3 | Layer, get_solver 4 | from .proto.caffe_pb2 import TRAIN, TEST 5 | from .classifier import Classifier 6 | from .detector import Detector 7 | import io 8 | -------------------------------------------------------------------------------- /caffe-wsl/python/caffe/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/python/caffe/__init__.pyc -------------------------------------------------------------------------------- /caffe-wsl/python/caffe/_caffe.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/python/caffe/_caffe.so -------------------------------------------------------------------------------- /caffe-wsl/python/caffe/classifier.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/python/caffe/classifier.pyc -------------------------------------------------------------------------------- /caffe-wsl/python/caffe/detector.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/python/caffe/detector.pyc -------------------------------------------------------------------------------- /caffe-wsl/python/caffe/imagenet/ilsvrc_2012_mean.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/python/caffe/imagenet/ilsvrc_2012_mean.npy -------------------------------------------------------------------------------- /caffe-wsl/python/caffe/io.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/python/caffe/io.pyc -------------------------------------------------------------------------------- /caffe-wsl/python/caffe/proto/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/python/caffe/proto/__init__.pyc -------------------------------------------------------------------------------- /caffe-wsl/python/caffe/proto/caffe_pb2.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/python/caffe/proto/caffe_pb2.pyc -------------------------------------------------------------------------------- /caffe-wsl/python/caffe/pycaffe.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/python/caffe/pycaffe.pyc -------------------------------------------------------------------------------- /caffe-wsl/python/draw_net.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Draw a graph of the net architecture. 4 | """ 5 | import argparse 6 | from google.protobuf import text_format 7 | 8 | import caffe 9 | import caffe.draw 10 | from caffe.proto import caffe_pb2 11 | 12 | 13 | def parse_args(): 14 | """Parse input arguments 15 | """ 16 | 17 | parser = argparse.ArgumentParser(description='Draw a network graph') 18 | 19 | parser.add_argument('input_net_proto_file', 20 | help='Input network prototxt file') 21 | parser.add_argument('output_image_file', 22 | help='Output image file') 23 | parser.add_argument('--rankdir', 24 | help=('One of TB (top-bottom, i.e., vertical), ' 25 | 'RL (right-left, i.e., horizontal), or another' 26 | 'valid dot option; see' 27 | 'http://www.graphviz.org/doc/info/attrs.html#k:rankdir' 28 | '(default: LR)'), 29 | default='LR') 30 | 31 | args = parser.parse_args() 32 | return args 33 | 34 | 35 | def main(): 36 | args = parse_args() 37 | net = caffe_pb2.NetParameter() 38 | text_format.Merge(open(args.input_net_proto_file).read(), net) 39 | print('Drawing net to %s' % args.output_image_file) 40 | caffe.draw.draw_net_to_file(net, args.output_image_file, args.rankdir) 41 | 42 | 43 | if __name__ == '__main__': 44 | main() 45 | -------------------------------------------------------------------------------- /caffe-wsl/python/requirements.txt: -------------------------------------------------------------------------------- 1 | Cython>=0.19.2 2 | numpy>=1.7.1 3 | scipy>=0.13.2 4 | scikit-image>=0.9.3 5 | matplotlib>=1.3.1 6 | ipython>=1.1.0 7 | h5py>=2.2.0 8 | leveldb>=0.191 9 | networkx>=1.8.1 10 | nose>=1.3.0 11 | pandas>=0.12.0 12 | python-dateutil>=1.4,<2 13 | protobuf>=2.5.0 14 | python-gflags>=2.0 15 | pyyaml>=3.10 16 | Pillow>=2.3.0 17 | -------------------------------------------------------------------------------- /caffe-wsl/scripts/build_docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Build documentation for display in web browser. 3 | 4 | PORT=${1:-4000} 5 | 6 | echo "usage: build_docs.sh [port]" 7 | 8 | # Find the docs dir, no matter where the script is called 9 | ROOT_DIR="$( cd "$(dirname "$0")"/.. ; pwd -P )" 10 | cd $ROOT_DIR 11 | 12 | # Gather docs. 13 | scripts/gather_examples.sh 14 | 15 | # Generate developer docs. 16 | make docs 17 | 18 | # Display docs using web server. 19 | cd docs 20 | jekyll serve -w -s . -d _site --port=$PORT 21 | -------------------------------------------------------------------------------- /caffe-wsl/scripts/copy_notebook.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Takes as arguments: 4 | 1. the path to a JSON file (such as an IPython notebook). 5 | 2. the path to output file 6 | 7 | If 'metadata' dict in the JSON file contains 'include_in_docs': true, 8 | then copies the file to output file, appending the 'metadata' property 9 | as YAML front-matter, adding the field 'category' with value 'notebook'. 10 | """ 11 | import os 12 | import sys 13 | import json 14 | 15 | filename = sys.argv[1] 16 | output_filename = sys.argv[2] 17 | content = json.load(open(filename)) 18 | 19 | if 'include_in_docs' in content['metadata'] and content['metadata']['include_in_docs']: 20 | yaml_frontmatter = ['---'] 21 | for key, val in content['metadata'].iteritems(): 22 | if key == 'example_name': 23 | key = 'title' 24 | if val == '': 25 | val = os.path.basename(filename) 26 | yaml_frontmatter.append('{}: {}'.format(key, val)) 27 | yaml_frontmatter += ['category: notebook'] 28 | yaml_frontmatter += ['original_path: ' + filename] 29 | 30 | with open(output_filename, 'w') as fo: 31 | fo.write('\n'.join(yaml_frontmatter + ['---']) + '\n') 32 | fo.write(open(filename).read()) 33 | -------------------------------------------------------------------------------- /caffe-wsl/scripts/download_model_from_gist.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | GIST=$1 4 | DIRNAME=${2:-./models} 5 | 6 | if [ -z $GIST ]; then 7 | echo "usage: download_model_from_gist.sh " 8 | exit 9 | fi 10 | 11 | GIST_DIR=$(echo $GIST | tr '/' '-') 12 | MODEL_DIR="$DIRNAME/$GIST_DIR" 13 | 14 | if [ -d $MODEL_DIR ]; then 15 | echo "$MODEL_DIR already exists! Please make sure you're not overwriting anything important!" 16 | exit 17 | fi 18 | 19 | echo "Downloading Caffe model info to $MODEL_DIR ..." 20 | mkdir -p $MODEL_DIR 21 | wget https://gist.github.com/$GIST/download -O $MODEL_DIR/gist.tar.gz 22 | tar xzf $MODEL_DIR/gist.tar.gz --directory=$MODEL_DIR --strip-components=1 23 | rm $MODEL_DIR/gist.tar.gz 24 | echo "Done" 25 | -------------------------------------------------------------------------------- /caffe-wsl/scripts/gather_examples.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Assemble documentation for the project into one directory via symbolic links. 3 | 4 | # Find the docs dir, no matter where the script is called 5 | ROOT_DIR="$( cd "$(dirname "$0")"/.. ; pwd -P )" 6 | cd $ROOT_DIR 7 | 8 | # Gather docs from examples/**/readme.md 9 | GATHERED_DIR=docs/gathered 10 | rm -r $GATHERED_DIR 11 | mkdir $GATHERED_DIR 12 | for README_FILENAME in $(find examples -iname "readme.md"); do 13 | # Only use file if it is to be included in docs. 14 | if grep -Fxq "include_in_docs: true" $README_FILENAME; then 15 | # Make link to readme.md in docs/gathered/. 16 | # Since everything is called readme.md, rename it by its dirname. 17 | README_DIRNAME=`dirname $README_FILENAME` 18 | DOCS_FILENAME=$GATHERED_DIR/$README_DIRNAME.md 19 | mkdir -p `dirname $DOCS_FILENAME` 20 | ln -s $ROOT_DIR/$README_FILENAME $DOCS_FILENAME 21 | fi 22 | done 23 | 24 | # Gather docs from examples/*.ipynb and add YAML front-matter. 25 | for NOTEBOOK_FILENAME in $(find examples -depth -iname "*.ipynb"); do 26 | DOCS_FILENAME=$GATHERED_DIR/$NOTEBOOK_FILENAME 27 | mkdir -p `dirname $DOCS_FILENAME` 28 | python scripts/copy_notebook.py $NOTEBOOK_FILENAME $DOCS_FILENAME 29 | done 30 | -------------------------------------------------------------------------------- /caffe-wsl/scripts/travis/travis_build_and_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Script called by Travis to do a CPU-only build of and test Caffe. 3 | 4 | set -e 5 | MAKE="make --jobs=$NUM_THREADS --keep-going" 6 | 7 | if $WITH_CMAKE; then 8 | mkdir build 9 | cd build 10 | cmake -DBUILD_python=ON -DCMAKE_BUILD_TYPE=Release -DCPU_ONLY=ON .. 11 | $MAKE 12 | if ! $WITH_CUDA; then 13 | $MAKE runtest 14 | $MAKE lint 15 | fi 16 | $MAKE clean 17 | cd - 18 | else 19 | if ! $WITH_CUDA; then 20 | export CPU_ONLY=1 21 | fi 22 | $MAKE all test pycaffe warn lint || true 23 | if ! $WITH_CUDA; then 24 | $MAKE runtest 25 | fi 26 | $MAKE all 27 | $MAKE test 28 | $MAKE pycaffe 29 | $MAKE pytest 30 | $MAKE warn 31 | if ! $WITH_CUDA; then 32 | $MAKE lint 33 | fi 34 | fi 35 | -------------------------------------------------------------------------------- /caffe-wsl/scripts/travis/travis_setup_makefile_config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | mv Makefile.config.example Makefile.config 6 | 7 | if $WITH_CUDA; then 8 | # Only generate compute_50. 9 | GENCODE="-gencode arch=compute_50,code=sm_50" 10 | GENCODE="$GENCODE -gencode arch=compute_50,code=compute_50" 11 | echo "CUDA_ARCH := $GENCODE" >> Makefile.config 12 | fi 13 | 14 | cat << 'EOF' >> Makefile.config 15 | ANACONDA_HOME := $(HOME)/miniconda 16 | PYTHON_INCLUDE := $(ANACONDA_HOME)/include \ 17 | $(ANACONDA_HOME)/include/python2.7 \ 18 | $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include 19 | PYTHON_LIB := $(ANACONDA_HOME)/lib 20 | INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include 21 | LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib 22 | WITH_PYTHON_LAYER := 1 23 | EOF 24 | -------------------------------------------------------------------------------- /caffe-wsl/scripts/upload_model_to_gist.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Check for valid directory 4 | DIRNAME=$1 5 | if [ ! -f $DIRNAME/readme.md ]; then 6 | echo "usage: upload_model_to_gist.sh " 7 | echo " /readme.md must exist" 8 | fi 9 | cd $DIRNAME 10 | FILES=`find . -maxdepth 1 -type f ! -name "*.caffemodel*" | xargs echo` 11 | 12 | # Check for gist tool. 13 | gist -v >/dev/null 2>&1 || { echo >&2 "I require 'gist' but it's not installed. Do 'gem install gist'."; exit 1; } 14 | 15 | NAME=`sed -n 's/^name:[[:space:]]*//p' readme.md` 16 | if [ -z "$NAME" ]; then 17 | echo " /readme.md must contain name field in the front-matter." 18 | fi 19 | 20 | GIST=`sed -n 's/^gist_id:[[:space:]]*//p' readme.md` 21 | if [ -z "$GIST" ]; then 22 | echo "Uploading new Gist" 23 | gist -p -d "$NAME" $FILES 24 | else 25 | echo "Updating existing Gist, id $GIST" 26 | gist -u $GIST -d "$NAME" $FILES 27 | fi 28 | 29 | RESULT=$? 30 | if [ $RESULT -eq 0 ]; then 31 | echo "You've uploaded your model!" 32 | echo "Don't forget to add the gist_id field to your /readme.md now!" 33 | echo "Run the command again after you do that, to make sure the Gist id propagates." 34 | echo "" 35 | echo "And do share your model over at https://github.com/BVLC/caffe/wiki/Model-Zoo" 36 | else 37 | echo "Something went wrong!" 38 | fi 39 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # generate protobuf sources 2 | file(GLOB proto_files proto/*.proto) 3 | caffe_protobuf_generate_cpp_py(${proto_gen_folder} proto_srcs proto_hdrs proto_python ${proto_files}) 4 | 5 | # include python files either to force generation 6 | add_library(proto STATIC ${proto_hdrs} ${proto_srcs} ${proto_python}) 7 | set(Caffe_LINKER_LIBS proto ${Caffe_LINKER_LIBS}) # note, crucial to prepend! 8 | caffe_default_properties(proto) 9 | 10 | # --[ Caffe library 11 | 12 | # creates 'test_srcs', 'srcs', 'test_cuda', 'cuda' lists 13 | caffe_pickup_caffe_sources(${PROJECT_SOURCE_DIR}) 14 | 15 | if(HAVE_CUDA) 16 | caffe_cuda_compile(cuda_objs ${cuda}) 17 | list(APPEND srcs ${cuda_objs} ${cuda}) 18 | endif() 19 | 20 | add_library(caffe ${srcs}) 21 | target_link_libraries(caffe proto ${Caffe_LINKER_LIBS}) 22 | caffe_default_properties(caffe) 23 | 24 | # ---[ Tests 25 | add_subdirectory(test) 26 | 27 | # ---[ Install 28 | install(DIRECTORY ${Caffe_INCLUDE_DIR}/caffe DESTINATION include) 29 | install(FILES ${proto_hdrs} DESTINATION include/caffe/proto) 30 | install(TARGETS caffe proto EXPORT CaffeTargets DESTINATION lib) 31 | 32 | file(WRITE ${PROJECT_BINARY_DIR}/__init__.py) 33 | list(APPEND proto_python ${PROJECT_BINARY_DIR}/__init__.py) 34 | install(PROGRAMS ${proto_python} DESTINATION python/caffe/proto) 35 | 36 | 37 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/internal_thread.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "caffe/internal_thread.hpp" 3 | 4 | namespace caffe { 5 | 6 | InternalThread::~InternalThread() { 7 | WaitForInternalThreadToExit(); 8 | } 9 | 10 | bool InternalThread::is_started() const { 11 | return thread_.get() != NULL && thread_->joinable(); 12 | } 13 | 14 | 15 | bool InternalThread::StartInternalThread() { 16 | if (!WaitForInternalThreadToExit()) { 17 | return false; 18 | } 19 | try { 20 | thread_.reset( 21 | new boost::thread(&InternalThread::InternalThreadEntry, this)); 22 | } catch (...) { 23 | return false; 24 | } 25 | return true; 26 | } 27 | 28 | /** Will not return until the internal thread has exited. */ 29 | bool InternalThread::WaitForInternalThreadToExit() { 30 | if (is_started()) { 31 | try { 32 | thread_->join(); 33 | } catch (...) { 34 | return false; 35 | } 36 | } 37 | return true; 38 | } 39 | 40 | } // namespace caffe 41 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/absval_layer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "caffe/layer.hpp" 4 | #include "caffe/neuron_layers.hpp" 5 | #include "caffe/util/math_functions.hpp" 6 | 7 | namespace caffe { 8 | 9 | template 10 | void AbsValLayer::LayerSetUp(const vector*>& bottom, 11 | const vector*>& top) { 12 | NeuronLayer::LayerSetUp(bottom, top); 13 | CHECK_NE(top[0], bottom[0]) << this->type() << " Layer does not " 14 | "allow in-place computation."; 15 | } 16 | 17 | template 18 | void AbsValLayer::Forward_cpu( 19 | const vector*>& bottom, const vector*>& top) { 20 | const int count = top[0]->count(); 21 | Dtype* top_data = top[0]->mutable_cpu_data(); 22 | caffe_abs(count, bottom[0]->cpu_data(), top_data); 23 | } 24 | 25 | template 26 | void AbsValLayer::Backward_cpu(const vector*>& top, 27 | const vector& propagate_down, const vector*>& bottom) { 28 | const int count = top[0]->count(); 29 | const Dtype* top_diff = top[0]->cpu_diff(); 30 | if (propagate_down[0]) { 31 | const Dtype* bottom_data = bottom[0]->cpu_data(); 32 | Dtype* bottom_diff = bottom[0]->mutable_cpu_diff(); 33 | caffe_cpu_sign(count, bottom_data, bottom_diff); 34 | caffe_mul(count, bottom_diff, top_diff, bottom_diff); 35 | } 36 | } 37 | 38 | #ifdef CPU_ONLY 39 | STUB_GPU(AbsValLayer); 40 | #endif 41 | 42 | INSTANTIATE_CLASS(AbsValLayer); 43 | REGISTER_LAYER_CLASS(AbsVal); 44 | 45 | } // namespace caffe 46 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/absval_layer.cu: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "caffe/layer.hpp" 4 | #include "caffe/util/math_functions.hpp" 5 | #include "caffe/vision_layers.hpp" 6 | 7 | namespace caffe { 8 | 9 | template 10 | void AbsValLayer::Forward_gpu( 11 | const vector*>& bottom, const vector*>& top) { 12 | const int count = top[0]->count(); 13 | Dtype* top_data = top[0]->mutable_gpu_data(); 14 | caffe_gpu_abs(count, bottom[0]->gpu_data(), top_data); 15 | } 16 | 17 | template 18 | void AbsValLayer::Backward_gpu(const vector*>& top, 19 | const vector& propagate_down, const vector*>& bottom) { 20 | const int count = top[0]->count(); 21 | const Dtype* top_data = top[0]->gpu_data(); 22 | const Dtype* top_diff = top[0]->gpu_diff(); 23 | if (propagate_down[0]) { 24 | const Dtype* bottom_data = bottom[0]->gpu_data(); 25 | Dtype* bottom_diff = bottom[0]->mutable_gpu_diff(); 26 | caffe_gpu_sign(count, bottom_data, bottom_diff); 27 | caffe_gpu_mul(count, bottom_diff, top_diff, bottom_diff); 28 | } 29 | } 30 | 31 | INSTANTIATE_LAYER_GPU_FUNCS(AbsValLayer); 32 | 33 | 34 | } // namespace caffe 35 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/base_data_layer.cu: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "caffe/data_layers.hpp" 4 | 5 | namespace caffe { 6 | 7 | template 8 | void BasePrefetchingDataLayer::Forward_gpu( 9 | const vector*>& bottom, const vector*>& top) { 10 | // First, join the thread 11 | JoinPrefetchThread(); 12 | // Reshape to loaded data. 13 | top[0]->Reshape(this->prefetch_data_.num(), this->prefetch_data_.channels(), 14 | this->prefetch_data_.height(), this->prefetch_data_.width()); 15 | // Copy the data 16 | caffe_copy(prefetch_data_.count(), prefetch_data_.cpu_data(), 17 | top[0]->mutable_gpu_data()); 18 | if (this->output_labels_) { 19 | caffe_copy(prefetch_label_.count(), prefetch_label_.cpu_data(), 20 | top[1]->mutable_gpu_data()); 21 | } 22 | // Start a new prefetch thread 23 | CreatePrefetchThread(); 24 | } 25 | 26 | INSTANTIATE_LAYER_GPU_FORWARD(BasePrefetchingDataLayer); 27 | 28 | } // namespace caffe 29 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/bnll_layer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "caffe/layer.hpp" 5 | #include "caffe/vision_layers.hpp" 6 | 7 | namespace caffe { 8 | 9 | const float kBNLL_THRESHOLD = 50.; 10 | 11 | template 12 | void BNLLLayer::Forward_cpu(const vector*>& bottom, 13 | const vector*>& top) { 14 | const Dtype* bottom_data = bottom[0]->cpu_data(); 15 | Dtype* top_data = top[0]->mutable_cpu_data(); 16 | const int count = bottom[0]->count(); 17 | for (int i = 0; i < count; ++i) { 18 | top_data[i] = bottom_data[i] > 0 ? 19 | bottom_data[i] + log(1. + exp(-bottom_data[i])) : 20 | log(1. + exp(bottom_data[i])); 21 | } 22 | } 23 | 24 | template 25 | void BNLLLayer::Backward_cpu(const vector*>& top, 26 | const vector& propagate_down, 27 | const vector*>& bottom) { 28 | if (propagate_down[0]) { 29 | const Dtype* bottom_data = bottom[0]->cpu_data(); 30 | const Dtype* top_diff = top[0]->cpu_diff(); 31 | Dtype* bottom_diff = bottom[0]->mutable_cpu_diff(); 32 | const int count = bottom[0]->count(); 33 | Dtype expval; 34 | for (int i = 0; i < count; ++i) { 35 | expval = exp(std::min(bottom_data[i], Dtype(kBNLL_THRESHOLD))); 36 | bottom_diff[i] = top_diff[i] * expval / (expval + 1.); 37 | } 38 | } 39 | } 40 | 41 | #ifdef CPU_ONLY 42 | STUB_GPU(BNLLLayer); 43 | #endif 44 | 45 | INSTANTIATE_CLASS(BNLLLayer); 46 | REGISTER_LAYER_CLASS(BNLL); 47 | 48 | } // namespace caffe 49 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/cudnn_pooling_layer.cu: -------------------------------------------------------------------------------- 1 | #ifdef USE_CUDNN 2 | #include 3 | 4 | #include "caffe/filler.hpp" 5 | #include "caffe/layer.hpp" 6 | #include "caffe/util/im2col.hpp" 7 | #include "caffe/util/math_functions.hpp" 8 | #include "caffe/vision_layers.hpp" 9 | 10 | namespace caffe { 11 | 12 | template 13 | void CuDNNPoolingLayer::Forward_gpu(const vector*>& bottom, 14 | const vector*>& top) { 15 | const Dtype* bottom_data = bottom[0]->gpu_data(); 16 | Dtype* top_data = top[0]->mutable_gpu_data(); 17 | CUDNN_CHECK(cudnnPoolingForward(handle_, pooling_desc_, 18 | cudnn::dataType::one, 19 | bottom_desc_, bottom_data, 20 | cudnn::dataType::zero, 21 | top_desc_, top_data)); 22 | } 23 | 24 | template 25 | void CuDNNPoolingLayer::Backward_gpu(const vector*>& top, 26 | const vector& propagate_down, const vector*>& bottom) { 27 | if (!propagate_down[0]) { 28 | return; 29 | } 30 | const Dtype* top_diff = top[0]->gpu_diff(); 31 | const Dtype* top_data = top[0]->gpu_data(); 32 | const Dtype* bottom_data = bottom[0]->gpu_data(); 33 | Dtype* bottom_diff = bottom[0]->mutable_gpu_diff(); 34 | CUDNN_CHECK(cudnnPoolingBackward(handle_, pooling_desc_, 35 | cudnn::dataType::one, 36 | top_desc_, top_data, top_desc_, top_diff, 37 | bottom_desc_, bottom_data, 38 | cudnn::dataType::zero, 39 | bottom_desc_, bottom_diff)); 40 | } 41 | 42 | INSTANTIATE_LAYER_GPU_FUNCS(CuDNNPoolingLayer); 43 | 44 | } // namespace caffe 45 | #endif 46 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/cudnn_relu_layer.cpp: -------------------------------------------------------------------------------- 1 | #ifdef USE_CUDNN 2 | #include 3 | #include 4 | 5 | #include "caffe/layer.hpp" 6 | #include "caffe/vision_layers.hpp" 7 | 8 | namespace caffe { 9 | 10 | template 11 | void CuDNNReLULayer::LayerSetUp(const vector*>& bottom, 12 | const vector*>& top) { 13 | ReLULayer::LayerSetUp(bottom, top); 14 | // initialize cuDNN 15 | CUDNN_CHECK(cudnnCreate(&handle_)); 16 | cudnn::createTensor4dDesc(&bottom_desc_); 17 | cudnn::createTensor4dDesc(&top_desc_); 18 | handles_setup_ = true; 19 | } 20 | 21 | template 22 | void CuDNNReLULayer::Reshape(const vector*>& bottom, 23 | const vector*>& top) { 24 | ReLULayer::Reshape(bottom, top); 25 | const int N = bottom[0]->num(); 26 | const int K = bottom[0]->channels(); 27 | const int H = bottom[0]->height(); 28 | const int W = bottom[0]->width(); 29 | cudnn::setTensor4dDesc(&bottom_desc_, N, K, H, W); 30 | cudnn::setTensor4dDesc(&top_desc_, N, K, H, W); 31 | } 32 | 33 | template 34 | CuDNNReLULayer::~CuDNNReLULayer() { 35 | // Check that handles have been setup before destroying. 36 | if (!handles_setup_) { return; } 37 | 38 | cudnnDestroyTensorDescriptor(this->bottom_desc_); 39 | cudnnDestroyTensorDescriptor(this->top_desc_); 40 | cudnnDestroy(this->handle_); 41 | } 42 | 43 | INSTANTIATE_CLASS(CuDNNReLULayer); 44 | 45 | } // namespace caffe 46 | #endif 47 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/cudnn_sigmoid_layer.cpp: -------------------------------------------------------------------------------- 1 | #ifdef USE_CUDNN 2 | #include 3 | #include 4 | 5 | #include "caffe/layer.hpp" 6 | #include "caffe/vision_layers.hpp" 7 | 8 | namespace caffe { 9 | 10 | template 11 | void CuDNNSigmoidLayer::LayerSetUp(const vector*>& bottom, 12 | const vector*>& top) { 13 | SigmoidLayer::LayerSetUp(bottom, top); 14 | // initialize cuDNN 15 | CUDNN_CHECK(cudnnCreate(&handle_)); 16 | cudnn::createTensor4dDesc(&bottom_desc_); 17 | cudnn::createTensor4dDesc(&top_desc_); 18 | handles_setup_ = true; 19 | } 20 | 21 | template 22 | void CuDNNSigmoidLayer::Reshape(const vector*>& bottom, 23 | const vector*>& top) { 24 | SigmoidLayer::Reshape(bottom, top); 25 | const int N = bottom[0]->num(); 26 | const int K = bottom[0]->channels(); 27 | const int H = bottom[0]->height(); 28 | const int W = bottom[0]->width(); 29 | cudnn::setTensor4dDesc(&bottom_desc_, N, K, H, W); 30 | cudnn::setTensor4dDesc(&top_desc_, N, K, H, W); 31 | } 32 | 33 | template 34 | CuDNNSigmoidLayer::~CuDNNSigmoidLayer() { 35 | // Check that handles have been setup before destroying. 36 | if (!handles_setup_) { return; } 37 | 38 | cudnnDestroyTensorDescriptor(this->bottom_desc_); 39 | cudnnDestroyTensorDescriptor(this->top_desc_); 40 | cudnnDestroy(this->handle_); 41 | } 42 | 43 | INSTANTIATE_CLASS(CuDNNSigmoidLayer); 44 | 45 | } // namespace caffe 46 | #endif 47 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/cudnn_sigmoid_layer.cu: -------------------------------------------------------------------------------- 1 | #ifdef USE_CUDNN 2 | #include 3 | #include 4 | 5 | #include "caffe/layer.hpp" 6 | #include "caffe/vision_layers.hpp" 7 | 8 | namespace caffe { 9 | 10 | template 11 | void CuDNNSigmoidLayer::Forward_gpu(const vector*>& bottom, 12 | const vector*>& top) { 13 | const Dtype* bottom_data = bottom[0]->gpu_data(); 14 | Dtype* top_data = top[0]->mutable_gpu_data(); 15 | CUDNN_CHECK(cudnnActivationForward(this->handle_, 16 | CUDNN_ACTIVATION_SIGMOID, 17 | cudnn::dataType::one, 18 | this->bottom_desc_, bottom_data, 19 | cudnn::dataType::zero, 20 | this->top_desc_, top_data)); 21 | } 22 | 23 | template 24 | void CuDNNSigmoidLayer::Backward_gpu(const vector*>& top, 25 | const vector& propagate_down, 26 | const vector*>& bottom) { 27 | if (!propagate_down[0]) { 28 | return; 29 | } 30 | 31 | const Dtype* top_data = top[0]->gpu_data(); 32 | const Dtype* top_diff = top[0]->gpu_diff(); 33 | const Dtype* bottom_data = bottom[0]->gpu_data(); 34 | Dtype* bottom_diff = bottom[0]->mutable_gpu_diff(); 35 | CUDNN_CHECK(cudnnActivationBackward(this->handle_, 36 | CUDNN_ACTIVATION_SIGMOID, 37 | cudnn::dataType::one, 38 | this->top_desc_, top_data, this->top_desc_, top_diff, 39 | this->bottom_desc_, bottom_data, 40 | cudnn::dataType::zero, 41 | this->bottom_desc_, bottom_diff)); 42 | } 43 | 44 | INSTANTIATE_LAYER_GPU_FUNCS(CuDNNSigmoidLayer); 45 | 46 | } // namespace caffe 47 | #endif 48 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/cudnn_softmax_layer.cpp: -------------------------------------------------------------------------------- 1 | #ifdef USE_CUDNN 2 | #include 3 | #include 4 | #include 5 | 6 | #include "thrust/device_vector.h" 7 | 8 | #include "caffe/layer.hpp" 9 | #include "caffe/util/math_functions.hpp" 10 | #include "caffe/vision_layers.hpp" 11 | 12 | namespace caffe { 13 | 14 | template 15 | void CuDNNSoftmaxLayer::LayerSetUp(const vector*>& bottom, 16 | const vector*>& top) { 17 | SoftmaxLayer::LayerSetUp(bottom, top); 18 | // Initialize CUDNN. 19 | CUDNN_CHECK(cudnnCreate(&handle_)); 20 | cudnn::createTensor4dDesc(&bottom_desc_); 21 | cudnn::createTensor4dDesc(&top_desc_); 22 | handles_setup_ = true; 23 | } 24 | 25 | template 26 | void CuDNNSoftmaxLayer::Reshape(const vector*>& bottom, 27 | const vector*>& top) { 28 | SoftmaxLayer::Reshape(bottom, top); 29 | int N = this->outer_num_; 30 | int K = bottom[0]->shape(this->softmax_axis_); 31 | int H = this->inner_num_; 32 | int W = 1; 33 | cudnn::setTensor4dDesc(&bottom_desc_, N, K, H, W); 34 | cudnn::setTensor4dDesc(&top_desc_, N, K, H, W); 35 | } 36 | 37 | template 38 | CuDNNSoftmaxLayer::~CuDNNSoftmaxLayer() { 39 | // Check that handles have been setup before destroying. 40 | if (!handles_setup_) { return; } 41 | 42 | cudnnDestroyTensorDescriptor(bottom_desc_); 43 | cudnnDestroyTensorDescriptor(top_desc_); 44 | cudnnDestroy(handle_); 45 | } 46 | 47 | INSTANTIATE_CLASS(CuDNNSoftmaxLayer); 48 | 49 | } // namespace caffe 50 | #endif 51 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/cudnn_tanh_layer.cpp: -------------------------------------------------------------------------------- 1 | #ifdef USE_CUDNN 2 | #include 3 | #include 4 | 5 | #include "caffe/layer.hpp" 6 | #include "caffe/vision_layers.hpp" 7 | 8 | namespace caffe { 9 | 10 | template 11 | void CuDNNTanHLayer::LayerSetUp(const vector*>& bottom, 12 | const vector*>& top) { 13 | TanHLayer::LayerSetUp(bottom, top); 14 | // initialize cuDNN 15 | CUDNN_CHECK(cudnnCreate(&handle_)); 16 | cudnn::createTensor4dDesc(&bottom_desc_); 17 | cudnn::createTensor4dDesc(&top_desc_); 18 | handles_setup_ = true; 19 | } 20 | 21 | template 22 | void CuDNNTanHLayer::Reshape(const vector*>& bottom, 23 | const vector*>& top) { 24 | TanHLayer::Reshape(bottom, top); 25 | const int N = bottom[0]->num(); 26 | const int K = bottom[0]->channels(); 27 | const int H = bottom[0]->height(); 28 | const int W = bottom[0]->width(); 29 | cudnn::setTensor4dDesc(&bottom_desc_, N, K, H, W); 30 | cudnn::setTensor4dDesc(&top_desc_, N, K, H, W); 31 | } 32 | 33 | template 34 | CuDNNTanHLayer::~CuDNNTanHLayer() { 35 | // Check that handles have been setup before destroying. 36 | if (!handles_setup_) { return; } 37 | 38 | cudnnDestroyTensorDescriptor(this->bottom_desc_); 39 | cudnnDestroyTensorDescriptor(this->top_desc_); 40 | cudnnDestroy(this->handle_); 41 | } 42 | 43 | INSTANTIATE_CLASS(CuDNNTanHLayer); 44 | 45 | } // namespace caffe 46 | #endif 47 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/cudnn_tanh_layer.cu: -------------------------------------------------------------------------------- 1 | #ifdef USE_CUDNN 2 | #include 3 | #include 4 | 5 | #include "caffe/layer.hpp" 6 | #include "caffe/vision_layers.hpp" 7 | 8 | namespace caffe { 9 | 10 | template 11 | void CuDNNTanHLayer::Forward_gpu(const vector*>& bottom, 12 | const vector*>& top) { 13 | const Dtype* bottom_data = bottom[0]->gpu_data(); 14 | Dtype* top_data = top[0]->mutable_gpu_data(); 15 | CUDNN_CHECK(cudnnActivationForward(this->handle_, 16 | CUDNN_ACTIVATION_TANH, 17 | cudnn::dataType::one, 18 | this->bottom_desc_, bottom_data, 19 | cudnn::dataType::zero, 20 | this->top_desc_, top_data)); 21 | } 22 | 23 | template 24 | void CuDNNTanHLayer::Backward_gpu(const vector*>& top, 25 | const vector& propagate_down, 26 | const vector*>& bottom) { 27 | if (!propagate_down[0]) { 28 | return; 29 | } 30 | 31 | const Dtype* top_data = top[0]->gpu_data(); 32 | const Dtype* top_diff = top[0]->gpu_diff(); 33 | const Dtype* bottom_data = bottom[0]->gpu_data(); 34 | Dtype* bottom_diff = bottom[0]->mutable_gpu_diff(); 35 | 36 | CUDNN_CHECK(cudnnActivationBackward(this->handle_, 37 | CUDNN_ACTIVATION_TANH, 38 | cudnn::dataType::one, 39 | this->top_desc_, top_data, this->top_desc_, top_diff, 40 | this->bottom_desc_, bottom_data, 41 | cudnn::dataType::zero, 42 | this->bottom_desc_, bottom_diff)); 43 | } 44 | 45 | INSTANTIATE_LAYER_GPU_FUNCS(CuDNNTanHLayer); 46 | 47 | } // namespace caffe 48 | #endif 49 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/euclidean_loss_layer.cu: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "caffe/layer.hpp" 4 | #include "caffe/util/io.hpp" 5 | #include "caffe/util/math_functions.hpp" 6 | #include "caffe/vision_layers.hpp" 7 | 8 | namespace caffe { 9 | 10 | template 11 | void EuclideanLossLayer::Forward_gpu(const vector*>& bottom, 12 | const vector*>& top) { 13 | int count = bottom[0]->count(); 14 | caffe_gpu_sub( 15 | count, 16 | bottom[0]->gpu_data(), 17 | bottom[1]->gpu_data(), 18 | diff_.mutable_gpu_data()); 19 | Dtype dot; 20 | caffe_gpu_dot(count, diff_.gpu_data(), diff_.gpu_data(), &dot); 21 | Dtype loss = dot / bottom[0]->num() / Dtype(2); 22 | top[0]->mutable_cpu_data()[0] = loss; 23 | } 24 | 25 | template 26 | void EuclideanLossLayer::Backward_gpu(const vector*>& top, 27 | const vector& propagate_down, const vector*>& bottom) { 28 | for (int i = 0; i < 2; ++i) { 29 | if (propagate_down[i]) { 30 | const Dtype sign = (i == 0) ? 1 : -1; 31 | const Dtype alpha = sign * top[0]->cpu_diff()[0] / bottom[i]->num(); 32 | caffe_gpu_axpby( 33 | bottom[i]->count(), // count 34 | alpha, // alpha 35 | diff_.gpu_data(), // a 36 | Dtype(0), // beta 37 | bottom[i]->mutable_gpu_diff()); // b 38 | } 39 | } 40 | } 41 | 42 | INSTANTIATE_LAYER_GPU_FUNCS(EuclideanLossLayer); 43 | 44 | } // namespace caffe 45 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/exp_layer.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "caffe/layer.hpp" 5 | #include "caffe/util/math_functions.hpp" 6 | #include "caffe/vision_layers.hpp" 7 | 8 | namespace caffe { 9 | 10 | template 11 | void ExpLayer::Forward_gpu(const vector*>& bottom, 12 | const vector*>& top) { 13 | const int count = bottom[0]->count(); 14 | const Dtype* bottom_data = bottom[0]->gpu_data(); 15 | Dtype* top_data = top[0]->mutable_gpu_data(); 16 | if (inner_scale_ == Dtype(1)) { 17 | caffe_gpu_exp(count, bottom_data, top_data); 18 | } else { 19 | caffe_gpu_scale(count, inner_scale_, bottom_data, top_data); 20 | caffe_gpu_exp(count, top_data, top_data); 21 | } 22 | if (outer_scale_ != Dtype(1)) { 23 | caffe_gpu_scal(count, outer_scale_, top_data); 24 | } 25 | } 26 | 27 | template 28 | void ExpLayer::Backward_gpu(const vector*>& top, 29 | const vector& propagate_down, const vector*>& bottom) { 30 | if (!propagate_down[0]) { return; } 31 | const int count = bottom[0]->count(); 32 | const Dtype* top_data = top[0]->gpu_data(); 33 | const Dtype* top_diff = top[0]->gpu_diff(); 34 | Dtype* bottom_diff = bottom[0]->mutable_gpu_diff(); 35 | caffe_gpu_mul(count, top_data, top_diff, bottom_diff); 36 | if (inner_scale_ != Dtype(1)) { 37 | caffe_gpu_scal(count, inner_scale_, bottom_diff); 38 | } 39 | } 40 | 41 | INSTANTIATE_LAYER_GPU_FUNCS(ExpLayer); 42 | 43 | 44 | } // namespace caffe 45 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/flatten_layer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "caffe/layer.hpp" 4 | #include "caffe/util/math_functions.hpp" 5 | #include "caffe/vision_layers.hpp" 6 | 7 | namespace caffe { 8 | 9 | template 10 | void FlattenLayer::Reshape(const vector*>& bottom, 11 | const vector*>& top) { 12 | vector top_shape(2); 13 | top_shape[0] = bottom[0]->num(); 14 | top_shape[1] = bottom[0]->count() / bottom[0]->num(); 15 | top[0]->Reshape(top_shape); 16 | CHECK_EQ(top[0]->count(), bottom[0]->count()); 17 | } 18 | 19 | template 20 | void FlattenLayer::Forward_cpu(const vector*>& bottom, 21 | const vector*>& top) { 22 | top[0]->ShareData(*bottom[0]); 23 | } 24 | 25 | template 26 | void FlattenLayer::Backward_cpu(const vector*>& top, 27 | const vector& propagate_down, const vector*>& bottom) { 28 | bottom[0]->ShareDiff(*top[0]); 29 | } 30 | 31 | INSTANTIATE_CLASS(FlattenLayer); 32 | REGISTER_LAYER_CLASS(Flatten); 33 | 34 | } // namespace caffe 35 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/hdf5_output_layer.cu: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "hdf5.h" 4 | #include "hdf5_hl.h" 5 | 6 | #include "caffe/blob.hpp" 7 | #include "caffe/common.hpp" 8 | #include "caffe/layer.hpp" 9 | #include "caffe/util/io.hpp" 10 | #include "caffe/vision_layers.hpp" 11 | 12 | namespace caffe { 13 | 14 | template 15 | void HDF5OutputLayer::Forward_gpu(const vector*>& bottom, 16 | const vector*>& top) { 17 | CHECK_GE(bottom.size(), 2); 18 | CHECK_EQ(bottom[0]->num(), bottom[1]->num()); 19 | data_blob_.Reshape(bottom[0]->num(), bottom[0]->channels(), 20 | bottom[0]->height(), bottom[0]->width()); 21 | label_blob_.Reshape(bottom[1]->num(), bottom[1]->channels(), 22 | bottom[1]->height(), bottom[1]->width()); 23 | const int data_datum_dim = bottom[0]->count() / bottom[0]->num(); 24 | const int label_datum_dim = bottom[1]->count() / bottom[1]->num(); 25 | 26 | for (int i = 0; i < bottom[0]->num(); ++i) { 27 | caffe_copy(data_datum_dim, &bottom[0]->gpu_data()[i * data_datum_dim], 28 | &data_blob_.mutable_cpu_data()[i * data_datum_dim]); 29 | caffe_copy(label_datum_dim, &bottom[1]->gpu_data()[i * label_datum_dim], 30 | &label_blob_.mutable_cpu_data()[i * label_datum_dim]); 31 | } 32 | SaveBlobs(); 33 | } 34 | 35 | template 36 | void HDF5OutputLayer::Backward_gpu(const vector*>& top, 37 | const vector& propagate_down, const vector*>& bottom) { 38 | return; 39 | } 40 | 41 | INSTANTIATE_LAYER_GPU_FUNCS(HDF5OutputLayer); 42 | 43 | } // namespace caffe 44 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/im2col_layer.cu: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "caffe/common.hpp" 4 | #include "caffe/layer.hpp" 5 | #include "caffe/util/im2col.hpp" 6 | #include "caffe/vision_layers.hpp" 7 | 8 | namespace caffe { 9 | 10 | template 11 | void Im2colLayer::Forward_gpu(const vector*>& bottom, 12 | const vector*>& top) { 13 | const Dtype* bottom_data = bottom[0]->gpu_data(); 14 | Dtype* top_data = top[0]->mutable_gpu_data(); 15 | for (int n = 0; n < bottom[0]->num(); ++n) { 16 | im2col_gpu(bottom_data + bottom[0]->offset(n), channels_, height_, 17 | width_, kernel_h_, kernel_w_, pad_h_, pad_w_, 18 | stride_h_, stride_w_, top_data + top[0]->offset(n)); 19 | } 20 | } 21 | 22 | template 23 | void Im2colLayer::Backward_gpu(const vector*>& top, 24 | const vector& propagate_down, const vector*>& bottom) { 25 | const Dtype* top_diff = top[0]->gpu_diff(); 26 | Dtype* bottom_diff = bottom[0]->mutable_gpu_diff(); 27 | for (int n = 0; n < top[0]->num(); ++n) { 28 | col2im_gpu(top_diff + top[0]->offset(n), channels_, height_, width_, 29 | kernel_h_, kernel_w_, pad_h_, pad_w_, 30 | stride_h_, stride_w_, bottom_diff + bottom[0]->offset(n)); 31 | } 32 | } 33 | 34 | 35 | INSTANTIATE_LAYER_GPU_FUNCS(Im2colLayer); 36 | 37 | } // namespace caffe 38 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/loss_layer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "caffe/layer.hpp" 7 | #include "caffe/util/io.hpp" 8 | #include "caffe/util/math_functions.hpp" 9 | #include "caffe/vision_layers.hpp" 10 | 11 | namespace caffe { 12 | 13 | template 14 | void LossLayer::LayerSetUp( 15 | const vector*>& bottom, const vector*>& top) { 16 | // LossLayers have a non-zero (1) loss by default. 17 | if (this->layer_param_.loss_weight_size() == 0) { 18 | this->layer_param_.add_loss_weight(Dtype(1)); 19 | } 20 | } 21 | 22 | template 23 | void LossLayer::Reshape( 24 | const vector*>& bottom, const vector*>& top) { 25 | CHECK_EQ(bottom[0]->num(), bottom[1]->num()) 26 | << "The data and label should have the same number."; 27 | vector loss_shape(0); // Loss layers output a scalar; 0 axes. 28 | top[0]->Reshape(loss_shape); 29 | } 30 | 31 | INSTANTIATE_CLASS(LossLayer); 32 | 33 | } // namespace caffe 34 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/neuron_layer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "caffe/layer.hpp" 4 | #include "caffe/vision_layers.hpp" 5 | 6 | namespace caffe { 7 | 8 | template 9 | void NeuronLayer::Reshape(const vector*>& bottom, 10 | const vector*>& top) { 11 | top[0]->ReshapeLike(*bottom[0]); 12 | } 13 | 14 | INSTANTIATE_CLASS(NeuronLayer); 15 | 16 | } // namespace caffe 17 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/relu_layer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "caffe/layer.hpp" 5 | #include "caffe/vision_layers.hpp" 6 | 7 | namespace caffe { 8 | 9 | template 10 | void ReLULayer::Forward_cpu(const vector*>& bottom, 11 | const vector*>& top) { 12 | const Dtype* bottom_data = bottom[0]->cpu_data(); 13 | Dtype* top_data = top[0]->mutable_cpu_data(); 14 | const int count = bottom[0]->count(); 15 | Dtype negative_slope = this->layer_param_.relu_param().negative_slope(); 16 | for (int i = 0; i < count; ++i) { 17 | top_data[i] = std::max(bottom_data[i], Dtype(0)) 18 | + negative_slope * std::min(bottom_data[i], Dtype(0)); 19 | } 20 | } 21 | 22 | template 23 | void ReLULayer::Backward_cpu(const vector*>& top, 24 | const vector& propagate_down, 25 | const vector*>& bottom) { 26 | if (propagate_down[0]) { 27 | const Dtype* bottom_data = bottom[0]->cpu_data(); 28 | const Dtype* top_diff = top[0]->cpu_diff(); 29 | Dtype* bottom_diff = bottom[0]->mutable_cpu_diff(); 30 | const int count = bottom[0]->count(); 31 | Dtype negative_slope = this->layer_param_.relu_param().negative_slope(); 32 | for (int i = 0; i < count; ++i) { 33 | bottom_diff[i] = top_diff[i] * ((bottom_data[i] > 0) 34 | + negative_slope * (bottom_data[i] <= 0)); 35 | } 36 | } 37 | } 38 | 39 | 40 | #ifdef CPU_ONLY 41 | STUB_GPU(ReLULayer); 42 | #endif 43 | 44 | INSTANTIATE_CLASS(ReLULayer); 45 | 46 | } // namespace caffe 47 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/sigmoid_layer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "caffe/layer.hpp" 6 | #include "caffe/vision_layers.hpp" 7 | 8 | namespace caffe { 9 | 10 | template 11 | inline Dtype sigmoid(Dtype x) { 12 | return 1. / (1. + exp(-x)); 13 | } 14 | 15 | template 16 | void SigmoidLayer::Forward_cpu(const vector*>& bottom, 17 | const vector*>& top) { 18 | const Dtype* bottom_data = bottom[0]->cpu_data(); 19 | Dtype* top_data = top[0]->mutable_cpu_data(); 20 | const int count = bottom[0]->count(); 21 | for (int i = 0; i < count; ++i) { 22 | top_data[i] = sigmoid(bottom_data[i]); 23 | } 24 | } 25 | 26 | template 27 | void SigmoidLayer::Backward_cpu(const vector*>& top, 28 | const vector& propagate_down, 29 | const vector*>& bottom) { 30 | if (propagate_down[0]) { 31 | const Dtype* top_data = top[0]->cpu_data(); 32 | const Dtype* top_diff = top[0]->cpu_diff(); 33 | Dtype* bottom_diff = bottom[0]->mutable_cpu_diff(); 34 | const int count = bottom[0]->count(); 35 | for (int i = 0; i < count; ++i) { 36 | const Dtype sigmoid_x = top_data[i]; 37 | bottom_diff[i] = top_diff[i] * sigmoid_x * (1. - sigmoid_x); 38 | } 39 | } 40 | } 41 | 42 | #ifdef CPU_ONLY 43 | STUB_GPU(SigmoidLayer); 44 | #endif 45 | 46 | INSTANTIATE_CLASS(SigmoidLayer); 47 | 48 | 49 | } // namespace caffe 50 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/silence_layer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "caffe/common_layers.hpp" 4 | #include "caffe/layer.hpp" 5 | #include "caffe/util/math_functions.hpp" 6 | 7 | namespace caffe { 8 | 9 | template 10 | void SilenceLayer::Backward_cpu(const vector*>& top, 11 | const vector& propagate_down, const vector*>& bottom) { 12 | for (int i = 0; i < bottom.size(); ++i) { 13 | if (propagate_down[i]) { 14 | caffe_set(bottom[i]->count(), Dtype(0), 15 | bottom[i]->mutable_cpu_data()); 16 | } 17 | } 18 | } 19 | 20 | #ifdef CPU_ONLY 21 | STUB_GPU(SilenceLayer); 22 | #endif 23 | 24 | INSTANTIATE_CLASS(SilenceLayer); 25 | REGISTER_LAYER_CLASS(Silence); 26 | 27 | } // namespace caffe 28 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/silence_layer.cu: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "caffe/common_layers.hpp" 4 | #include "caffe/layer.hpp" 5 | #include "caffe/util/math_functions.hpp" 6 | 7 | namespace caffe { 8 | 9 | template 10 | void SilenceLayer::Forward_gpu(const vector*>& bottom, 11 | const vector*>& top) { 12 | // Do nothing. 13 | } 14 | 15 | template 16 | void SilenceLayer::Backward_gpu(const vector*>& top, 17 | const vector& propagate_down, const vector*>& bottom) { 18 | for (int i = 0; i < bottom.size(); ++i) { 19 | if (propagate_down[i]) { 20 | caffe_gpu_set(bottom[i]->count(), Dtype(0), 21 | bottom[i]->mutable_gpu_data()); 22 | } 23 | } 24 | } 25 | 26 | INSTANTIATE_LAYER_GPU_FUNCS(SilenceLayer); 27 | 28 | } // namespace caffe 29 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/split_layer.cu: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "caffe/layer.hpp" 4 | #include "caffe/util/math_functions.hpp" 5 | #include "caffe/vision_layers.hpp" 6 | 7 | namespace caffe { 8 | 9 | template 10 | void SplitLayer::Forward_gpu(const vector*>& bottom, 11 | const vector*>& top) { 12 | for (int i = 0; i < top.size(); ++i) { 13 | top[i]->ShareData(*bottom[0]); 14 | } 15 | } 16 | 17 | template 18 | void SplitLayer::Backward_gpu(const vector*>& top, 19 | const vector& propagate_down, const vector*>& bottom) { 20 | if (!propagate_down[0]) { return; } 21 | if (top.size() == 1) { 22 | caffe_copy(count_, top[0]->gpu_diff(), bottom[0]->mutable_gpu_diff()); 23 | return; 24 | } 25 | caffe_gpu_add(count_, top[0]->gpu_diff(), top[1]->gpu_diff(), 26 | bottom[0]->mutable_gpu_diff()); 27 | // Add remaining top blob diffs. 28 | for (int i = 2; i < top.size(); ++i) { 29 | const Dtype* top_diff = top[i]->gpu_diff(); 30 | Dtype* bottom_diff = bottom[0]->mutable_gpu_diff(); 31 | caffe_gpu_axpy(count_, Dtype(1.), top_diff, bottom_diff); 32 | } 33 | } 34 | 35 | 36 | INSTANTIATE_LAYER_GPU_FUNCS(SplitLayer); 37 | 38 | } // namespace caffe 39 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/tanh_layer.cpp: -------------------------------------------------------------------------------- 1 | // TanH neuron activation function layer. 2 | // Adapted from ReLU layer code written by Yangqing Jia 3 | 4 | #include 5 | #include 6 | 7 | #include "caffe/layer.hpp" 8 | #include "caffe/vision_layers.hpp" 9 | 10 | namespace caffe { 11 | 12 | template 13 | void TanHLayer::Forward_cpu(const vector*>& bottom, 14 | const vector*>& top) { 15 | const Dtype* bottom_data = bottom[0]->cpu_data(); 16 | Dtype* top_data = top[0]->mutable_cpu_data(); 17 | const int count = bottom[0]->count(); 18 | for (int i = 0; i < count; ++i) { 19 | top_data[i] = tanh(bottom_data[i]); 20 | } 21 | } 22 | 23 | template 24 | void TanHLayer::Backward_cpu(const vector*>& top, 25 | const vector& propagate_down, 26 | const vector*>& bottom) { 27 | if (propagate_down[0]) { 28 | const Dtype* top_data = top[0]->cpu_data(); 29 | const Dtype* top_diff = top[0]->cpu_diff(); 30 | Dtype* bottom_diff = bottom[0]->mutable_cpu_diff(); 31 | const int count = bottom[0]->count(); 32 | Dtype tanhx; 33 | for (int i = 0; i < count; ++i) { 34 | tanhx = top_data[i]; 35 | bottom_diff[i] = top_diff[i] * (1 - tanhx * tanhx); 36 | } 37 | } 38 | } 39 | 40 | #ifdef CPU_ONLY 41 | STUB_GPU(TanHLayer); 42 | #endif 43 | 44 | INSTANTIATE_CLASS(TanHLayer); 45 | 46 | } // namespace caffe 47 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/threshold_layer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "caffe/layer.hpp" 4 | #include "caffe/vision_layers.hpp" 5 | 6 | 7 | namespace caffe { 8 | 9 | template 10 | void ThresholdLayer::LayerSetUp(const vector*>& bottom, 11 | const vector*>& top) { 12 | NeuronLayer::LayerSetUp(bottom, top); 13 | threshold_ = this->layer_param_.threshold_param().threshold(); 14 | } 15 | 16 | template 17 | void ThresholdLayer::Forward_cpu(const vector*>& bottom, 18 | const vector*>& top) { 19 | const Dtype* bottom_data = bottom[0]->cpu_data(); 20 | Dtype* top_data = top[0]->mutable_cpu_data(); 21 | const int count = bottom[0]->count(); 22 | for (int i = 0; i < count; ++i) { 23 | top_data[i] = (bottom_data[i] > threshold_) ? Dtype(1) : Dtype(0); 24 | } 25 | } 26 | 27 | #ifdef CPU_ONLY 28 | STUB_GPU_FORWARD(ThresholdLayer, Forward); 29 | #endif 30 | 31 | INSTANTIATE_CLASS(ThresholdLayer); 32 | REGISTER_LAYER_CLASS(Threshold); 33 | 34 | } // namespace caffe 35 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/layers/threshold_layer.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "caffe/layer.hpp" 5 | #include "caffe/vision_layers.hpp" 6 | 7 | namespace caffe { 8 | 9 | template 10 | __global__ void ThresholdForward(const int n, const Dtype threshold, 11 | const Dtype* in, Dtype* out) { 12 | CUDA_KERNEL_LOOP(index, n) { 13 | out[index] = in[index] > threshold ? 1 : 0; 14 | } 15 | } 16 | 17 | template 18 | void ThresholdLayer::Forward_gpu(const vector*>& bottom, 19 | const vector*>& top) { 20 | const Dtype* bottom_data = bottom[0]->gpu_data(); 21 | Dtype* top_data = top[0]->mutable_gpu_data(); 22 | const int count = bottom[0]->count(); 23 | // NOLINT_NEXT_LINE(whitespace/operators) 24 | ThresholdForward<<>>( 25 | count, threshold_, bottom_data, top_data); 26 | CUDA_POST_KERNEL_CHECK; 27 | } 28 | 29 | 30 | INSTANTIATE_LAYER_GPU_FORWARD(ThresholdLayer); 31 | 32 | 33 | } // namespace caffe 34 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The option allows to include in build only selected test files and exclude all others 2 | # Usage example: 3 | # cmake -DBUILD_only_tests="common,net,blob,im2col_kernel" 4 | set(BUILD_only_tests "" CACHE STRING "Blank or comma-separated list of test files to build without 'test_' prefix and extention") 5 | caffe_leave_only_selected_tests(test_srcs ${BUILD_only_tests}) 6 | caffe_leave_only_selected_tests(test_cuda ${BUILD_only_tests}) 7 | 8 | # For 'make runtest' target we don't need to embed test data paths to 9 | # source files, because test target is executed in source directory 10 | # That's why the lines below are commented. TODO: remove them 11 | 12 | # definition needed to include CMake generated files 13 | #add_definitions(-DCMAKE_BUILD) 14 | 15 | # generates test_data/sample_data_list.txt.gen.cmake 16 | #caffe_configure_testdatafile(test_data/sample_data_list.txt) 17 | 18 | set(the_target test.testbin) 19 | set(test_args --gtest_shuffle) 20 | 21 | if(HAVE_CUDA) 22 | caffe_cuda_compile(test_cuda_objs ${test_cuda}) 23 | list(APPEND test_srcs ${test_cuda_objs} ${test_cuda}) 24 | else() 25 | list(APPEND test_args --gtest_filter="-*GPU*") 26 | endif() 27 | 28 | # ---[ Adding test target 29 | add_executable(${the_target} EXCLUDE_FROM_ALL ${test_srcs}) 30 | target_link_libraries(${the_target} gtest ${Caffe_LINK}) 31 | caffe_default_properties(${the_target}) 32 | caffe_set_runtime_directory(${the_target} "${PROJECT_BINARY_DIR}/test") 33 | 34 | # ---[ Adding runtest 35 | add_custom_target(runtest COMMAND ${the_target} ${test_args} 36 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) 37 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/test/test_caffe_main.cpp: -------------------------------------------------------------------------------- 1 | // The main caffe test code. Your test cpp code should include this hpp 2 | // to allow a main function to be compiled into the binary. 3 | 4 | #include "caffe/caffe.hpp" 5 | #include "caffe/test/test_caffe_main.hpp" 6 | 7 | namespace caffe { 8 | #ifndef CPU_ONLY 9 | cudaDeviceProp CAFFE_TEST_CUDA_PROP; 10 | #endif 11 | } 12 | 13 | #ifndef CPU_ONLY 14 | using caffe::CAFFE_TEST_CUDA_PROP; 15 | #endif 16 | 17 | int main(int argc, char** argv) { 18 | ::testing::InitGoogleTest(&argc, argv); 19 | caffe::GlobalInit(&argc, &argv); 20 | #ifndef CPU_ONLY 21 | // Before starting testing, let's first print out a few cuda defice info. 22 | int device; 23 | cudaGetDeviceCount(&device); 24 | cout << "Cuda number of devices: " << device << endl; 25 | if (argc > 1) { 26 | // Use the given device 27 | device = atoi(argv[1]); 28 | cudaSetDevice(device); 29 | cout << "Setting to use device " << device << endl; 30 | } else if (CUDA_TEST_DEVICE >= 0) { 31 | // Use the device assigned in build configuration; but with a lower priority 32 | device = CUDA_TEST_DEVICE; 33 | } 34 | cudaGetDevice(&device); 35 | cout << "Current device id: " << device << endl; 36 | cudaGetDeviceProperties(&CAFFE_TEST_CUDA_PROP, device); 37 | #endif 38 | // invoke the test. 39 | return RUN_ALL_TESTS(); 40 | } 41 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/test/test_data/generate_sample_data.py: -------------------------------------------------------------------------------- 1 | """ 2 | Generate data used in the HDF5DataLayer test. 3 | """ 4 | import os 5 | import numpy as np 6 | import h5py 7 | 8 | num_cols = 8 9 | num_rows = 10 10 | height = 6 11 | width = 5 12 | total_size = num_cols * num_rows * height * width 13 | 14 | data = np.arange(total_size) 15 | data = data.reshape(num_rows, num_cols, height, width) 16 | data = data.astype('float32') 17 | 18 | # We had a bug where data was copied into label, but the tests weren't 19 | # catching it, so let's make label 1-indexed. 20 | label = 1 + np.arange(num_rows)[:, np.newaxis] 21 | label = label.astype('float32') 22 | 23 | # We add an extra label2 dataset to test HDF5 layer's ability 24 | # to handle arbitrary number of output ("top") Blobs. 25 | label2 = label + 1 26 | 27 | print data 28 | print label 29 | 30 | with h5py.File(os.path.dirname(__file__) + '/sample_data.h5', 'w') as f: 31 | f['data'] = data 32 | f['label'] = label 33 | f['label2'] = label2 34 | 35 | with h5py.File(os.path.dirname(__file__) + '/sample_data_2_gzip.h5', 'w') as f: 36 | f.create_dataset( 37 | 'data', data=data + total_size, 38 | compression='gzip', compression_opts=1 39 | ) 40 | f.create_dataset( 41 | 'label', data=label, 42 | compression='gzip', compression_opts=1 43 | ) 44 | f.create_dataset( 45 | 'label2', data=label2, 46 | compression='gzip', compression_opts=1 47 | ) 48 | 49 | with open(os.path.dirname(__file__) + '/sample_data_list.txt', 'w') as f: 50 | f.write(os.path.dirname(__file__) + '/sample_data.h5\n') 51 | f.write(os.path.dirname(__file__) + '/sample_data_2_gzip.h5\n') 52 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/test/test_data/sample_data.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/src/caffe/test/test_data/sample_data.h5 -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/test/test_data/sample_data_2_gzip.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/caffe-wsl/src/caffe/test/test_data/sample_data_2_gzip.h5 -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/test/test_data/sample_data_list.txt: -------------------------------------------------------------------------------- 1 | src/caffe/test/test_data/sample_data.h5 2 | src/caffe/test/test_data/sample_data_2_gzip.h5 3 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/test/test_internal_thread.cpp: -------------------------------------------------------------------------------- 1 | #include "glog/logging.h" 2 | #include "gtest/gtest.h" 3 | 4 | #include "caffe/internal_thread.hpp" 5 | 6 | #include "caffe/test/test_caffe_main.hpp" 7 | 8 | namespace caffe { 9 | 10 | 11 | class InternalThreadTest : public ::testing::Test {}; 12 | 13 | TEST_F(InternalThreadTest, TestStartAndExit) { 14 | InternalThread thread; 15 | EXPECT_FALSE(thread.is_started()); 16 | EXPECT_TRUE(thread.StartInternalThread()); 17 | EXPECT_TRUE(thread.is_started()); 18 | EXPECT_TRUE(thread.WaitForInternalThreadToExit()); 19 | EXPECT_FALSE(thread.is_started()); 20 | } 21 | 22 | } // namespace caffe 23 | 24 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/test/test_layer_factory.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "gtest/gtest.h" 5 | 6 | #include "caffe/common.hpp" 7 | #include "caffe/layer.hpp" 8 | #include "caffe/layer_factory.hpp" 9 | 10 | #include "caffe/test/test_caffe_main.hpp" 11 | 12 | namespace caffe { 13 | 14 | template 15 | class LayerFactoryTest : public MultiDeviceTest {}; 16 | 17 | TYPED_TEST_CASE(LayerFactoryTest, TestDtypesAndDevices); 18 | 19 | TYPED_TEST(LayerFactoryTest, TestCreateLayer) { 20 | typedef typename TypeParam::Dtype Dtype; 21 | typename LayerRegistry::CreatorRegistry& registry = 22 | LayerRegistry::Registry(); 23 | shared_ptr > layer; 24 | LayerParameter layer_param; 25 | for (typename LayerRegistry::CreatorRegistry::iterator iter = 26 | registry.begin(); iter != registry.end(); ++iter) { 27 | // Special case: PythonLayer is checked by pytest 28 | if (iter->first == "Python") { continue; } 29 | layer_param.set_type(iter->first); 30 | layer = LayerRegistry::CreateLayer(layer_param); 31 | EXPECT_EQ(iter->first, layer->type()); 32 | } 33 | } 34 | 35 | } // namespace caffe 36 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/test/test_protobuf.cpp: -------------------------------------------------------------------------------- 1 | // This is simply a script that tries serializing protocol buffer in text 2 | // format. Nothing special here and no actual code is being tested. 3 | #include 4 | 5 | #include "google/protobuf/text_format.h" 6 | #include "gtest/gtest.h" 7 | 8 | #include "caffe/proto/caffe.pb.h" 9 | 10 | #include "caffe/test/test_caffe_main.hpp" 11 | 12 | namespace caffe { 13 | 14 | class ProtoTest : public ::testing::Test {}; 15 | 16 | TEST_F(ProtoTest, TestSerialization) { 17 | LayerParameter param; 18 | param.set_name("test"); 19 | param.set_type("Test"); 20 | std::cout << "Printing in binary format." << std::endl; 21 | std::cout << param.SerializeAsString() << std::endl; 22 | std::cout << "Printing in text format." << std::endl; 23 | std::string str; 24 | google::protobuf::TextFormat::PrintToString(param, &str); 25 | std::cout << str << std::endl; 26 | EXPECT_TRUE(true); 27 | } 28 | 29 | } // namespace caffe 30 | -------------------------------------------------------------------------------- /caffe-wsl/src/caffe/util/cudnn.cpp: -------------------------------------------------------------------------------- 1 | #ifdef USE_CUDNN 2 | #include "caffe/util/cudnn.hpp" 3 | 4 | namespace caffe { 5 | namespace cudnn { 6 | 7 | float dataType::oneval = 1.0; 8 | float dataType::zeroval = 0.0; 9 | const void* dataType::one = 10 | static_cast(&dataType::oneval); 11 | const void* dataType::zero = 12 | static_cast(&dataType::zeroval); 13 | 14 | double dataType::oneval = 1.0; 15 | double dataType::zeroval = 0.0; 16 | const void* dataType::one = 17 | static_cast(&dataType::oneval); 18 | const void* dataType::zero = 19 | static_cast(&dataType::zeroval); 20 | 21 | } // namespace cudnn 22 | } // namespace caffe 23 | #endif 24 | -------------------------------------------------------------------------------- /caffe-wsl/src/gtest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(gtest STATIC EXCLUDE_FROM_ALL gtest.h gtest-all.cpp) 2 | caffe_default_properties(gtest) 3 | 4 | #add_library(gtest_main gtest_main.cc) 5 | #target_link_libraries(gtest_main gtest) 6 | -------------------------------------------------------------------------------- /caffe-wsl/tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Collect source files 2 | file(GLOB_RECURSE srcs ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 3 | 4 | # Build each source file independently 5 | foreach(source ${srcs}) 6 | get_filename_component(name ${source} NAME_WE) 7 | 8 | # caffe target already exits 9 | if(name MATCHES "caffe") 10 | set(name ${name}.bin) 11 | endif() 12 | 13 | # target 14 | add_executable(${name} ${source}) 15 | target_link_libraries(${name} ${Caffe_LINK}) 16 | caffe_default_properties(${name}) 17 | 18 | # set back RUNTIME_OUTPUT_DIRECTORY 19 | caffe_set_runtime_directory(${name} "${PROJECT_BINARY_DIR}/tools") 20 | caffe_set_solution_folder(${name} tools) 21 | 22 | # restore output name without suffix 23 | if(name MATCHES "caffe.bin") 24 | set_target_properties(${name} PROPERTIES OUTPUT_NAME caffe) 25 | endif() 26 | 27 | # Install 28 | install(TARGETS ${name} DESTINATION bin) 29 | endforeach(source) 30 | -------------------------------------------------------------------------------- /caffe-wsl/tools/device_query.cpp: -------------------------------------------------------------------------------- 1 | #include "caffe/common.hpp" 2 | 3 | int main(int argc, char** argv) { 4 | LOG(FATAL) << "Deprecated. Use caffe device_query " 5 | "[--device_id=0] instead."; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /caffe-wsl/tools/extra/launch_resize_and_crop_images.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #### https://github.com/Yangqing/mincepie/wiki/Launch-Your-Mapreducer 3 | 4 | # If you encounter error that the address already in use, kill the process. 5 | # 11235 is the port of server process 6 | # https://github.com/Yangqing/mincepie/blob/master/mincepie/mince.py 7 | # sudo netstat -ap | grep 11235 8 | # The last column of the output is PID/Program name 9 | # kill -9 PID 10 | # Second solution: 11 | # nmap localhost 12 | # fuser -k 11235/tcp 13 | # Or just wait a few seconds. 14 | 15 | ## Launch your Mapreduce locally 16 | # num_clients: number of processes 17 | # image_lib: OpenCV or PIL, case insensitive. The default value is the faster OpenCV. 18 | # input: the file containing one image path relative to input_folder each line 19 | # input_folder: where are the original images 20 | # output_folder: where to save the resized and cropped images 21 | ./resize_and_crop_images.py --num_clients=8 --image_lib=opencv --input=/home/user/Datasets/ImageNet/ILSVRC2010/ILSVRC2010_images.txt --input_folder=/home/user/Datasets/ImageNet/ILSVRC2010/ILSVRC2010_images_train/ --output_folder=/home/user/Datasets/ImageNet/ILSVRC2010/ILSVRC2010_images_train_resized/ 22 | 23 | ## Launch your Mapreduce with MPI 24 | # mpirun -n 8 --launch=mpi resize_and_crop_images.py --image_lib=opencv --input=/home/user/Datasets/ImageNet/ILSVRC2010/ILSVRC2010_images.txt --input_folder=/home/user/Datasets/ImageNet/ILSVRC2010/ILSVRC2010_images_train/ --output_folder=/home/user/Datasets/ImageNet/ILSVRC2010/ILSVRC2010_images_train_resized/ 25 | -------------------------------------------------------------------------------- /caffe-wsl/tools/finetune_net.cpp: -------------------------------------------------------------------------------- 1 | #include "caffe/caffe.hpp" 2 | 3 | int main(int argc, char** argv) { 4 | LOG(FATAL) << "Deprecated. Use caffe train --solver=... " 5 | "[--weights=...] instead."; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /caffe-wsl/tools/net_speed_benchmark.cpp: -------------------------------------------------------------------------------- 1 | #include "caffe/caffe.hpp" 2 | 3 | int main(int argc, char** argv) { 4 | LOG(FATAL) << "Deprecated. Use caffe time --model=... " 5 | "[--iterations=50] [--gpu] [--device_id=0]"; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /caffe-wsl/tools/test_net.cpp: -------------------------------------------------------------------------------- 1 | #include "caffe/caffe.hpp" 2 | 3 | int main(int argc, char** argv) { 4 | LOG(FATAL) << "Deprecated. Use caffe test --model=... " 5 | "--weights=... instead."; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /caffe-wsl/tools/train_net.cpp: -------------------------------------------------------------------------------- 1 | #include "caffe/caffe.hpp" 2 | 3 | int main(int argc, char** argv) { 4 | LOG(FATAL) << "Deprecated. Use caffe train --solver=... " 5 | "[--snapshot=...] instead."; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /cls_adapt.sh: -------------------------------------------------------------------------------- 1 | ./caffe-wsl/build/tools/caffe train -gpu 0 -solver prototxt/cls_adapt_solver.prototxt -weights data/imagenet_models/bvlc_reference_caffenet.caffemodel 2>&1 | tee log_cls_adapt.txt 2 | -------------------------------------------------------------------------------- /data/edgebox_data/README.md: -------------------------------------------------------------------------------- 1 | 2 | Extracted object proposals using EdgeBox are saved in this directory. 3 | -------------------------------------------------------------------------------- /data/imagenet_models/README.md: -------------------------------------------------------------------------------- 1 | 2 | Pre-trained ImageNet models are saved in this directory. 3 | -------------------------------------------------------------------------------- /data/pylintrc: -------------------------------------------------------------------------------- 1 | [TYPECHECK] 2 | 3 | ignored-modules = numpy, numpy.random, cv2 4 | -------------------------------------------------------------------------------- /det_adapt.sh: -------------------------------------------------------------------------------- 1 | python ./tools/train_net.py --gpu 0 --solver prototxt/det_adapt_solver.prototxt --weights caffenet_cls_adapt_iter_10000.caffemodel 2>&1 | tee log_det_adapt.txt 2 | -------------------------------------------------------------------------------- /features/cache_bb_features.m: -------------------------------------------------------------------------------- 1 | % AUTORIGHTS 2 | % --------------------------------------------------------- 3 | % Copyright (c) 2014, Ross Girshick 4 | % Copyright (c) 2016, Dong Li 5 | % 6 | % This file is part of the WSL code and is available 7 | % under the terms of the MIT License provided in 8 | % LICENSE. Please retain this notice and LICENSE if you use 9 | % this file (or any portion of it) in your project. 10 | % --------------------------------------------------------- 11 | 12 | function feat = cache_bb_features(im, boxes, opts, flag) 13 | 14 | [batches, batch_padding] = extract_regions(im, boxes, opts, flag); 15 | batch_size = opts.batch_size; 16 | 17 | % compute features for each batch of region images 18 | feat_dim = -1; 19 | feat = []; 20 | curr = 1; 21 | for j = 1:length(batches) 22 | % forward propagate batch of region images 23 | f = caffe('forward', batches(j)); 24 | f = f{1}; 25 | f = f(:); 26 | 27 | % first batch, init feat_dim and feat 28 | if j == 1 29 | feat_dim = length(f)/batch_size; 30 | feat = zeros(size(boxes,1), feat_dim, 'single'); 31 | end 32 | 33 | f = reshape(f, [feat_dim batch_size]); 34 | 35 | % last batch, trim f to size 36 | if j == length(batches) 37 | if batch_padding > 0 38 | f = f(:, 1:end-batch_padding); 39 | end 40 | end 41 | 42 | feat(curr:curr+size(f,2)-1,:) = f'; 43 | curr = curr + batch_size; 44 | end 45 | -------------------------------------------------------------------------------- /features/extract_region_in.m: -------------------------------------------------------------------------------- 1 | % AUTORIGHTS 2 | % --------------------------------------------------------- 3 | % Copyright (c) 2016, Dong Li 4 | % 5 | % This file is part of the WSL code and is available 6 | % under the terms of the MIT License provided in 7 | % LICENSE. Please retain this notice and LICENSE if you use 8 | % this file (or any portion of it) in your project. 9 | % --------------------------------------------------------- 10 | 11 | function im_in = extract_region_in(im, bbox) 12 | 13 | crop_size = 227; 14 | padding = 16; 15 | scale = crop_size/(crop_size - padding*2); 16 | half_height = (bbox(4)-bbox(2)+1)/2; 17 | half_width = (bbox(3)-bbox(1)+1)/2; 18 | center = [bbox(1)+half_width bbox(2)+half_height]; 19 | bbox = round([center center] + [-half_width -half_height half_width half_height]*scale); 20 | bbox(1) = max(1, bbox(1)); 21 | bbox(2) = max(1, bbox(2)); 22 | bbox(3) = min(size(im,2), bbox(3)); 23 | bbox(4) = min(size(im,1), bbox(4)); 24 | im_in = im(bbox(2):bbox(4),bbox(1):bbox(3),:); 25 | im_in = preprocess(im_in); 26 | -------------------------------------------------------------------------------- /features/extract_region_out.m: -------------------------------------------------------------------------------- 1 | % AUTORIGHTS 2 | % --------------------------------------------------------- 3 | % Copyright (c) 2016, Dong Li 4 | % 5 | % This file is part of the WSL code and is available 6 | % under the terms of the MIT License provided in 7 | % LICENSE. Please retain this notice and LICENSE if you use 8 | % this file (or any portion of it) in your project. 9 | % --------------------------------------------------------- 10 | 11 | function im_out = extract_region_out(im, bbox) 12 | 13 | im_out = im; 14 | bbox(1) = max(1, bbox(1)); 15 | bbox(2) = max(1, bbox(2)); 16 | bbox(3) = min(size(im,2), bbox(3)); 17 | bbox(4) = min(size(im,1), bbox(4)); 18 | im_out(bbox(2):bbox(4),bbox(1):bbox(3),1) = 123; 19 | im_out(bbox(2):bbox(4),bbox(1):bbox(3),2) = 117; 20 | im_out(bbox(2):bbox(4),bbox(1):bbox(3),3) = 104; 21 | im_out = preprocess(im_out); 22 | -------------------------------------------------------------------------------- /features/preprocess.m: -------------------------------------------------------------------------------- 1 | % AUTORIGHTS 2 | % --------------------------------------------------------- 3 | % Copyright (c) 2016, Dong Li 4 | % 5 | % This file is part of the WSL code and is available 6 | % under the terms of the MIT License provided in 7 | % LICENSE. Please retain this notice and LICENSE if you use 8 | % this file (or any portion of it) in your project. 9 | % --------------------------------------------------------- 10 | 11 | function im = preprocess(im) 12 | 13 | im = imresize(im, [227 227], 'bilinear'); 14 | % permute from RGB to BGR and subtract the data mean 15 | im = im(:,:,[3 2 1]); % RGB to BGR 16 | im(:,:,1) = im(:,:,1) - 104; % subtract B mean 104 17 | im(:,:,2) = im(:,:,2) - 117; % subtract G mean 117 18 | im(:,:,3) = im(:,:,3) - 123; % subtract R mean 123 19 | % make width the fastest dimension, convert to single 20 | im = permute(im, [2 1 3]); 21 | -------------------------------------------------------------------------------- /imdb/cache/README.md: -------------------------------------------------------------------------------- 1 | 2 | IMDB image database and regions of interest database are saved in this directory. 3 | -------------------------------------------------------------------------------- /imdb/get_voc_opts.m: -------------------------------------------------------------------------------- 1 | function VOCopts = get_voc_opts(path) 2 | 3 | tmp = pwd; 4 | cd(path); 5 | try 6 | addpath('VOCcode'); 7 | VOCinit; 8 | catch 9 | rmpath('VOCcode'); 10 | cd(tmp); 11 | error(sprintf('VOCcode directory not found under %s', path)); 12 | end 13 | rmpath('VOCcode'); 14 | cd(tmp); 15 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | python setup.py build_ext --inplace 3 | rm -rf build 4 | -------------------------------------------------------------------------------- /lib/datasets/VOCdevkit-matlab-wrapper/get_voc_opts.m: -------------------------------------------------------------------------------- 1 | function VOCopts = get_voc_opts(path) 2 | 3 | tmp = pwd; 4 | cd(path); 5 | try 6 | addpath('VOCcode'); 7 | VOCinit; 8 | catch 9 | rmpath('VOCcode'); 10 | cd(tmp); 11 | error(sprintf('VOCcode directory not found under %s', path)); 12 | end 13 | rmpath('VOCcode'); 14 | cd(tmp); 15 | -------------------------------------------------------------------------------- /lib/datasets/VOCdevkit-matlab-wrapper/xVOCap.m: -------------------------------------------------------------------------------- 1 | function ap = xVOCap(rec,prec) 2 | % From the PASCAL VOC 2011 devkit 3 | 4 | mrec=[0 ; rec ; 1]; 5 | mpre=[0 ; prec ; 0]; 6 | for i=numel(mpre)-1:-1:1 7 | mpre(i)=max(mpre(i),mpre(i+1)); 8 | end 9 | i=find(mrec(2:end)~=mrec(1:end-1))+1; 10 | ap=sum((mrec(i)-mrec(i-1)).*mpre(i)); 11 | -------------------------------------------------------------------------------- /lib/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------- 2 | # Fast R-CNN 3 | # Copyright (c) 2015 Microsoft 4 | # Licensed under The MIT License [see LICENSE for details] 5 | # Written by Ross Girshick 6 | # -------------------------------------------------------- 7 | 8 | from .imdb import imdb 9 | from .pascal_voc import pascal_voc 10 | from . import factory 11 | 12 | import os.path as osp 13 | ROOT_DIR = osp.join(osp.dirname(__file__), '..', '..') 14 | 15 | # We assume your matlab binary is in your path and called `matlab'. 16 | # If either is not true, just add it to your path and alias it as matlab, or 17 | # you could change this file. 18 | MATLAB = 'matlab' 19 | 20 | # http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python 21 | def _which(program): 22 | import os 23 | def is_exe(fpath): 24 | return os.path.isfile(fpath) and os.access(fpath, os.X_OK) 25 | 26 | fpath, fname = os.path.split(program) 27 | if fpath: 28 | if is_exe(program): 29 | return program 30 | else: 31 | for path in os.environ["PATH"].split(os.pathsep): 32 | path = path.strip('"') 33 | exe_file = os.path.join(path, program) 34 | if is_exe(exe_file): 35 | return exe_file 36 | 37 | return None 38 | 39 | if _which(MATLAB) is None: 40 | msg = ("MATLAB command '{}' not found. " 41 | "Please add '{}' to your PATH.").format(MATLAB, MATLAB) 42 | raise EnvironmentError(msg) 43 | -------------------------------------------------------------------------------- /lib/datasets/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/datasets/__init__.pyc -------------------------------------------------------------------------------- /lib/datasets/factory.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/datasets/factory.pyc -------------------------------------------------------------------------------- /lib/datasets/imdb.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/datasets/imdb.pyc -------------------------------------------------------------------------------- /lib/datasets/pascal_voc.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/datasets/pascal_voc.pyc -------------------------------------------------------------------------------- /lib/fast_rcnn/__init__.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------- 2 | # Fast R-CNN 3 | # Copyright (c) 2015 Microsoft 4 | # Licensed under The MIT License [see LICENSE for details] 5 | # Written by Ross Girshick 6 | # -------------------------------------------------------- 7 | 8 | from . import config 9 | from . import train 10 | from . import test 11 | -------------------------------------------------------------------------------- /lib/fast_rcnn/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/fast_rcnn/__init__.pyc -------------------------------------------------------------------------------- /lib/fast_rcnn/config.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/fast_rcnn/config.pyc -------------------------------------------------------------------------------- /lib/fast_rcnn/test.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/fast_rcnn/test.pyc -------------------------------------------------------------------------------- /lib/fast_rcnn/train.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/fast_rcnn/train.pyc -------------------------------------------------------------------------------- /lib/roi_data_layer/__init__.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------- 2 | # Fast R-CNN 3 | # Copyright (c) 2015 Microsoft 4 | # Licensed under The MIT License [see LICENSE for details] 5 | # Written by Ross Girshick 6 | # -------------------------------------------------------- 7 | -------------------------------------------------------------------------------- /lib/roi_data_layer/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/roi_data_layer/__init__.pyc -------------------------------------------------------------------------------- /lib/roi_data_layer/layer.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/roi_data_layer/layer.pyc -------------------------------------------------------------------------------- /lib/roi_data_layer/minibatch.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/roi_data_layer/minibatch.pyc -------------------------------------------------------------------------------- /lib/roi_data_layer/roidb.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/roi_data_layer/roidb.pyc -------------------------------------------------------------------------------- /lib/setup.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------- 2 | # Fast R-CNN 3 | # Copyright (c) 2015 Microsoft 4 | # Licensed under The MIT License [see LICENSE for details] 5 | # Written by Ross Girshick 6 | # -------------------------------------------------------- 7 | 8 | import numpy as np 9 | from distutils.core import setup 10 | from distutils.extension import Extension 11 | from Cython.Distutils import build_ext 12 | 13 | cmdclass = {} 14 | ext_modules = [ 15 | Extension( 16 | "utils.cython_bbox", 17 | ["utils/bbox.pyx"], 18 | extra_compile_args=["-Wno-cpp", "-Wno-unused-function"], 19 | ), 20 | Extension( 21 | "utils.cython_nms", 22 | ["utils/nms.pyx"], 23 | extra_compile_args=["-Wno-cpp", "-Wno-unused-function"], 24 | ) 25 | ] 26 | cmdclass.update({'build_ext': build_ext}) 27 | 28 | setup( 29 | name='fast_rcnn', 30 | cmdclass=cmdclass, 31 | ext_modules=ext_modules, 32 | include_dirs=[np.get_include()] 33 | ) 34 | -------------------------------------------------------------------------------- /lib/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------- 2 | # Fast R-CNN 3 | # Copyright (c) 2015 Microsoft 4 | # Licensed under The MIT License [see LICENSE for details] 5 | # Written by Ross Girshick 6 | # -------------------------------------------------------- 7 | -------------------------------------------------------------------------------- /lib/utils/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/utils/__init__.pyc -------------------------------------------------------------------------------- /lib/utils/blob.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/utils/blob.pyc -------------------------------------------------------------------------------- /lib/utils/cython_bbox.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/utils/cython_bbox.so -------------------------------------------------------------------------------- /lib/utils/cython_nms.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/utils/cython_nms.so -------------------------------------------------------------------------------- /lib/utils/nms.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------- 2 | # Fast R-CNN 3 | # Copyright (c) 2015 Microsoft 4 | # Licensed under The MIT License [see LICENSE for details] 5 | # Written by Ross Girshick 6 | # -------------------------------------------------------- 7 | 8 | import numpy as np 9 | 10 | def nms(dets, thresh): 11 | x1 = dets[:, 0] 12 | y1 = dets[:, 1] 13 | x2 = dets[:, 2] 14 | y2 = dets[:, 3] 15 | scores = dets[:, 4] 16 | 17 | areas = (x2 - x1 + 1) * (y2 - y1 + 1) 18 | order = scores.argsort()[::-1] 19 | 20 | keep = [] 21 | while order.size > 0: 22 | i = order[0] 23 | keep.append(i) 24 | xx1 = np.maximum(x1[i], x1[order[1:]]) 25 | yy1 = np.maximum(y1[i], y1[order[1:]]) 26 | xx2 = np.minimum(x2[i], x2[order[1:]]) 27 | yy2 = np.minimum(y2[i], y2[order[1:]]) 28 | 29 | w = np.maximum(0.0, xx2 - xx1 + 1) 30 | h = np.maximum(0.0, yy2 - yy1 + 1) 31 | inter = w * h 32 | ovr = inter / (areas[i] + areas[order[1:]] - inter) 33 | 34 | inds = np.where(ovr <= thresh)[0] 35 | order = order[inds + 1] 36 | 37 | return keep 38 | -------------------------------------------------------------------------------- /lib/utils/timer.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------- 2 | # Fast R-CNN 3 | # Copyright (c) 2015 Microsoft 4 | # Licensed under The MIT License [see LICENSE for details] 5 | # Written by Ross Girshick 6 | # -------------------------------------------------------- 7 | 8 | import time 9 | 10 | class Timer(object): 11 | """A simple timer.""" 12 | def __init__(self): 13 | self.total_time = 0. 14 | self.calls = 0 15 | self.start_time = 0. 16 | self.diff = 0. 17 | self.average_time = 0. 18 | 19 | def tic(self): 20 | # using time.time instead of time.clock because time time.clock 21 | # does not normalize for multithreading 22 | self.start_time = time.time() 23 | 24 | def toc(self, average=True): 25 | self.diff = time.time() - self.start_time 26 | self.total_time += self.diff 27 | self.calls += 1 28 | self.average_time = self.total_time / self.calls 29 | if average: 30 | return self.average_time 31 | else: 32 | return self.diff 33 | -------------------------------------------------------------------------------- /lib/utils/timer.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/lib/utils/timer.pyc -------------------------------------------------------------------------------- /maskout.m: -------------------------------------------------------------------------------- 1 | % AUTORIGHTS 2 | % --------------------------------------------------------- 3 | % Copyright (c) 2016, Dong Li 4 | % 5 | % This file is part of the WSL code and is available 6 | % under the terms of the MIT License provided in 7 | % LICENSE. Please retain this notice and LICENSE if you use 8 | % this file (or any portion of it) in your project. 9 | % --------------------------------------------------------- 10 | 11 | clear; close all; clc; 12 | 13 | net_file = 'caffenet_cls_adapt_iter_10000.caffemodel'; 14 | crop_mode = 'warp'; 15 | crop_padding = 16; 16 | VOCdevkit = './data/VOCdevkit2007'; 17 | imdb_train = imdb_from_voc(VOCdevkit, 'trainval', '2007'); 18 | cache_fc8_features(imdb_train, ... 19 | 'crop_mode', crop_mode, ... 20 | 'crop_padding', crop_padding, ... 21 | 'net_file', net_file, ... 22 | 'cache_name', 'voc_2007_trainval_fc8'); 23 | 24 | load('./imdb/cache/imdb_voc_2007_trainval.mat'); 25 | load('./imdb/cache/roidb_voc_2007_trainval.mat'); 26 | IND = cell(length(imdb.image_ids),1); 27 | for i = 1:length(imdb.image_ids) 28 | d = load(['./cache/voc_2007_trainval_fc8/' imdb.image_ids{i} '.mat']); 29 | gtcls = unique(d.class(d.gt==1)); 30 | feat_in = d.feat_in(d.gt~=1,1:2:end-1); 31 | feat_out = d.feat_out(d.gt~=1,1:2:end-1); 32 | bbs = d.boxes(d.gt~=1,:); 33 | dist = feat_in - feat_out; 34 | for cls = gtcls(:)' 35 | bbs_nms = nms([bbs,dist(:,cls)],0.3); 36 | num_top = min(size(bbs_nms,1),50); 37 | IND{i} = [IND{i};bbs_nms(1:num_top)]; 38 | end 39 | end 40 | save('results_maskout_regions.mat','IND'); 41 | exit; 42 | -------------------------------------------------------------------------------- /mil/SVM_Cost_L1hinge.m: -------------------------------------------------------------------------------- 1 | function [cost, grad] = SVM_Cost_L1hinge(w, X, y, C) 2 | 3 | % work with dense sparse matrix X and compute [cost,grad] for 4 | % L1hinge loss SVM 5 | 6 | % INPUT 7 | % X: num_data * feat_dim 8 | % y: num_data * 1 9 | 10 | % OUTPUT 11 | % cost: scalar 12 | % grad: feat_dim * 1 13 | 14 | scores = X*w; 15 | 16 | % cost 17 | margins = y .* scores; 18 | loss = max(0, 1 - margins); 19 | cost = 0.5*norm(w)^2 + C * sum(loss); 20 | 21 | % gradient 22 | margin_test = (margins < 1); 23 | 24 | % loss_grad = margin_test .* (-1*y); 25 | % loss_grad = bsxfun(@times, X', loss_grad'); 26 | % loss_grad = sum(loss_grad, 2); 27 | 28 | loss_grad_mat = ((margin_test .* (-1*y))' * X)'; 29 | 30 | %assert(norm(loss_grad- loss_grad_mat) < 1e-7); 31 | 32 | grad = w + C * loss_grad_mat; 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /mil/SVM_Cost_Logistic.m: -------------------------------------------------------------------------------- 1 | function [cost, grad] = SVM_Cost_Logistic(w, X, y, C) 2 | 3 | % work with dense sparse matrix X and compute [cost,grad] for 4 | % Logistic loss SVM 5 | 6 | % INPUT 7 | % X: num_data * feat_dim 8 | % y: num_data * 1 9 | 10 | % OUTPUT 11 | % cost: scalar 12 | % grad: feat_dim * 1 13 | 14 | num_data = size(X,1); 15 | feat_dim = size(X,2); 16 | 17 | scores = X*w; 18 | 19 | % cost 20 | s = -1* y .* scores; 21 | loss = zeros(num_data,1); 22 | loss(s<0) = log(1 + exp(s(s<0))); 23 | loss(s>=0) = s(s>=0) + log(1 + exp(-s(s>=0))); 24 | cost = 0.5*norm(w)^2 + C * sum(loss); 25 | 26 | % gradient 27 | % loss_grad = -1* y ./ (1 + exp(y .* scores)); 28 | % loss_grad = bsxfun(@times, X', loss_grad'); 29 | % loss_grad = sum(loss_grad,2); 30 | 31 | loss_grad_mat = ( (-1* y ./ (1 + exp(y .* scores)))' * X)'; 32 | 33 | grad = w + C * loss_grad_mat; 34 | -------------------------------------------------------------------------------- /mil/SVM_Cost_SmoothHinge.m: -------------------------------------------------------------------------------- 1 | function [cost, grad] = SVM_Cost_SmoothHinge(w, X, y, C, sharpness) 2 | 3 | % work with dense sparse matrix X and compute [cost,grad] for 4 | % L1hinge loss SVM 5 | 6 | % INPUT 7 | % X: num_data * feat_dim 8 | % y: num_data * 1 9 | 10 | % OUTPUT 11 | % cost: scalar 12 | % grad: feat_dim * 1 13 | 14 | if nargin < 5 15 | sharpness = 100; 16 | end 17 | 18 | scores = X*w; 19 | 20 | % cost 21 | margins = y .* scores; 22 | [loss, loss_grad] = general_smooth_hinge(margins, sharpness); 23 | cost = 0.5*norm(w)^2 + C * sum(loss); 24 | 25 | % gradient 26 | %loss_grad = loss_grad .* bag_labels; 27 | %loss_grad = bsxfun(@times, X', loss_grad'); 28 | 29 | loss_grad_mat = ((loss_grad .* y)' * X)'; 30 | 31 | grad = w + C * loss_grad_mat; 32 | -------------------------------------------------------------------------------- /mil/feat_stats_hos.m: -------------------------------------------------------------------------------- 1 | function [mean_norm, stdd] = feat_stats_hos(split, year, layer, fine_tuned) 2 | 3 | num_images = 200; 4 | boxes_per_image = 200; 5 | 6 | conf = voc_config('pascal.year', year); 7 | 8 | image_ids = textread(sprintf(conf.pascal.VOCopts.imgsetpath, split), '%s'); 9 | image_ids = image_ids(randperm(length(image_ids), num_images)); 10 | 11 | feat_opts.layer = layer; 12 | feat_opts.fine_tuned = fine_tuned; 13 | feat_opts.use_flipped = false; 14 | 15 | ns = []; 16 | for i = 1:length(image_ids) 17 | tic_toc_print('feat stats: %d/%d\n', i, length(image_ids)); 18 | d = load_cached_features_hos(split, year, image_ids{i}); 19 | %d.feat = xform_feat(d.feat, pwr); 20 | %d.feat = d.feat ./ 19.584 * 20; 21 | 22 | X = d.feat(randperm(size(d.feat,1), min(boxes_per_image, size(d.feat,1))), :); 23 | ns = cat(1, ns, sqrt(sum(X.^2, 2))); 24 | end 25 | 26 | mean_norm = mean(ns); 27 | stdd = std(ns); 28 | -------------------------------------------------------------------------------- /mil/general_smooth_hinge.m: -------------------------------------------------------------------------------- 1 | function [loss_list, grad_list] = general_smooth_hinge(z, alpha) 2 | 3 | % This code implements the generalized smooth hinge loss from 4 | % http://qwone.com/~jason/writing/smoothHinge.pdf 5 | % written by Hyun Oh Song 6 | 7 | % AUTORIGHTS 8 | % --------------------------------------------------------- 9 | % Copyright (c) 2014, Hyun Oh Song 10 | % 11 | % This file is part of the Song-ICML2014 code and is available 12 | % under the terms of the Simplified BSD License provided in 13 | % LICENSE. Please retain this notice and LICENSE if you use 14 | % this file (or any portion of it) in your project. 15 | % --------------------------------------------------------- 16 | 17 | if nargin < 2 18 | alpha = 100; 19 | end 20 | 21 | loss_list = zeros(length(z), 1); 22 | 23 | % vectorized version 24 | negs = find(z <= 0); 25 | loss_list(negs) = alpha/(alpha+1) - z(negs); 26 | 27 | supps = find(z >0 & z <1); 28 | loss_list(supps) = 1/(alpha+1)* z(supps).^(alpha+1) - z(supps) + alpha/(alpha+1); 29 | 30 | % compute gradient 31 | if nargout == 2 32 | grad_list = zeros(length(z), 1); 33 | 34 | % vectorized version 35 | grad_list(negs) = -1; 36 | grad_list(supps) = z(supps).^alpha - 1; 37 | else 38 | grad_list = nan; 39 | end 40 | -------------------------------------------------------------------------------- /mil/load_cached_features_hos.m: -------------------------------------------------------------------------------- 1 | function d = load_cached_features_hos(dataset, year, ids) 2 | 3 | base_path = ['../cache/voc_' year '_' dataset '_fc7']; 4 | file = sprintf('%s/%s.mat', base_path, ids); 5 | d = load(file); -------------------------------------------------------------------------------- /mil/minFunc_2012/autoDif/autoGrad.m: -------------------------------------------------------------------------------- 1 | function [f,g] = autoGrad(x,type,funObj,varargin) % [f,g] = autoGrad(x,useComplex,funObj,varargin) % % Numerically compute gradient of objective function from function values % % type = % 1 - forward-differencing (p+1 evaluations) % 2 - central-differencing (more accurate, but requires 2p evaluations) % 3 - complex-step derivative (most accurate and only requires p evaluations, but only works for certain objectives) p = length(x); if type == 1 % Use Finite Differencing f = funObj(x,varargin{:}); mu = 2*sqrt(1e-12)*(1+norm(x)); diff = zeros(p,1); for j = 1:p e_j = zeros(p,1); e_j(j) = 1; diff(j,1) = funObj(x + mu*e_j,varargin{:}); end g = (diff-f)/mu; elseif type == 3 % Use Complex Differentials mu = 1e-150; diff = zeros(p,1); for j = 1:p e_j = zeros(p,1); e_j(j) = 1; diff(j,1) = funObj(x + mu*i*e_j,varargin{:}); end f = mean(real(diff)); g = imag(diff)/mu; else % Use Central Differencing mu = 2*sqrt(1e-12)*(1+norm(x)); diff1 = zeros(p,1); diff2 = zeros(p,1); for j = 1:p e_j = zeros(p,1); e_j(j) = 1; diff1(j,1) = funObj(x + mu*e_j,varargin{:}); diff2(j,1) = funObj(x - mu*e_j,varargin{:}); end f = mean([diff1;diff2]); g = (diff1 - diff2)/(2*mu); end if 0 % DEBUG CODE [fReal gReal] = funObj(x,varargin{:}); [fReal f] [gReal g] diff pause; end -------------------------------------------------------------------------------- /mil/minFunc_2012/autoDif/autoHess.m: -------------------------------------------------------------------------------- 1 | function [f,g,H] = autoHess(x,type,funObj,varargin) % Numerically compute Hessian of objective function from gradient values p = length(x); if type == 1 % Use finite differencing mu = 2*sqrt(1e-12)*(1+norm(x)); [f,g] = funObj(x,varargin{:}); diff = zeros(p); for j = 1:p e_j = zeros(p,1); e_j(j) = 1; [f diff(:,j)] = funObj(x + mu*e_j,varargin{:}); end H = (diff-repmat(g,[1 p]))/mu; elseif type == 3 % Use Complex Differentials mu = 1e-150; diff = zeros(p); for j = 1:p e_j = zeros(p,1); e_j(j) = 1; [f(j) diff(:,j)] = funObj(x + mu*i*e_j,varargin{:}); end f = mean(real(f)); g = mean(real(diff),2); H = imag(diff)/mu; else % Use central differencing mu = 2*sqrt(1e-12)*(1+norm(x)); f1 = zeros(p,1); f2 = zeros(p,1); diff1 = zeros(p); diff2 = zeros(p); for j = 1:p e_j = zeros(p,1); e_j(j) = 1; [f1(j) diff1(:,j)] = funObj(x + mu*e_j,varargin{:}); [f2(j) diff2(:,j)] = funObj(x - mu*e_j,varargin{:}); end f = mean([f1;f2]); g = mean([diff1 diff2],2); H = (diff1-diff2)/(2*mu); end % Make sure H is symmetric H = (H+H')/2; if 0 % DEBUG CODE [fReal gReal HReal] = funObj(x,varargin{:}); [fReal f] [gReal g] [HReal H] pause; end -------------------------------------------------------------------------------- /mil/minFunc_2012/autoDif/autoHv.m: -------------------------------------------------------------------------------- 1 | function [Hv] = autoHv(v,x,g,useComplex,funObj,varargin) 2 | % [Hv] = autoHv(v,x,g,useComplex,funObj,varargin) 3 | % 4 | % Numerically compute Hessian-vector product H*v of funObj(x,varargin{:}) 5 | % based on gradient values 6 | 7 | if useComplex 8 | mu = 1e-150i; 9 | else 10 | mu = 2*sqrt(1e-12)*(1+norm(x))/norm(v); 11 | end 12 | [f,finDif] = funObj(x + v*mu,varargin{:}); 13 | Hv = (finDif-g)/mu; -------------------------------------------------------------------------------- /mil/minFunc_2012/autoDif/autoTensor.m: -------------------------------------------------------------------------------- 1 | function [f,g,H,T] = autoTensor(x,type,funObj,varargin) % [f,g,H,T] = autoTensor(x,useComplex,funObj,varargin) % Numerically compute Tensor of 3rd-derivatives of objective function from Hessian values p = length(x); if type == 2 mu = 2*sqrt(1e-12)*(1+norm(x)); f1 = zeros(p,1); f2 = zeros(p,2); g1 = zeros(p); g2 = zeros(p); diff = zeros(p,p,p); for j = 1:p e_j = zeros(p,1); e_j(j) = 1; [f1(j) g1(:,j) diff1(:,:,j)] = funObj(x + mu*e_j,varargin{:}); [f2(j) g2(:,j) diff2(:,:,j)] = funObj(x + mu*e_j,varargin{:}); end f = mean([f1;f2]); g = mean([g1 g2],2); H = mean(cat(3,diff1,diff2),3); T = (diff1-diff2)/(2*mu); elseif type == 3 % Use Complex Differentials mu = 1e-150; f = zeros(p,1); g = zeros(p); diff = zeros(p,p,p); for j = 1:p e_j = zeros(p,1); e_j(j) = 1; [f(j) g(:,j) diff(:,:,j)] = funObj(x + mu*i*e_j,varargin{:}); end f = mean(real(f)); g = mean(real(g),2); H = mean(real(diff),3); T = imag(diff)/mu; else % Use finite differencing mu = 2*sqrt(1e-12)*(1+norm(x)); [f,g,H] = funObj(x,varargin{:}); diff = zeros(p,p,p); for j = 1:p e_j = zeros(p,1); e_j(j) = 1; [~ ~ diff(:,:,j)] = funObj(x + mu*e_j,varargin{:}); end T = (diff-repmat(H,[1 1 p]))/mu; end -------------------------------------------------------------------------------- /mil/minFunc_2012/autoDif/derivativeCheck.m: -------------------------------------------------------------------------------- 1 | function diff = derivativeCheck(funObj,x,order,type,varargin) 2 | % diff = derivativeCheck(funObj,x,order,useComplex,varargin) 3 | % 4 | % type = 1 (simple forward-difference) 5 | % type = 2 (central differencing - default) 6 | % type = 3 (complex-step deriative) 7 | 8 | if nargin < 3 9 | order = 1; % Only check gradient by default 10 | if nargin < 4 11 | type = 2; % Use central-differencing by default 12 | end 13 | end 14 | 15 | if order == 2 16 | [f,g,H] = funObj(x,varargin{:}); 17 | 18 | fprintf('Checking Hessian...\n'); 19 | [f2,g2,H2] = autoHess(x,type,funObj,varargin{:}); 20 | 21 | fprintf('Max difference between user and numerical hessian: %e\n',max(abs(H(:)-H2(:)))); 22 | if max(abs(H(:)-H2(:))) > 1e-4 23 | H 24 | H2 25 | diff = abs(H-H2) 26 | pause; 27 | end 28 | else 29 | [f,g] = funObj(x,varargin{:}); 30 | 31 | fprintf('Checking Gradient...\n'); 32 | [f2,g2] = autoGrad(x,type,funObj,varargin{:}); 33 | 34 | fprintf('Max difference between user and numerical gradient: %e\n',max(abs(g-g2))); 35 | if max(abs(g-g2)) > 1e-4 36 | fprintf('User NumDif:\n'); 37 | [g g2] 38 | diff = abs(g-g2) 39 | pause 40 | end 41 | end 42 | 43 | -------------------------------------------------------------------------------- /mil/minFunc_2012/example_derivativeCheck.m: -------------------------------------------------------------------------------- 1 | clear all 2 | 3 | nInst = 250; 4 | nVars = 10; 5 | X = randn(nInst,nVars); 6 | w = randn(nVars,1); 7 | y = sign(X*w + randn(nInst,1)); 8 | 9 | wTest = randn(nVars,1); 10 | 11 | fprintf('Testing gradient using forward-differencing...\n'); 12 | order = 1; 13 | derivativeCheck(@LogisticLoss,wTest,order,1,X,y); 14 | 15 | fprintf('Testing gradient using central-differencing...\n'); 16 | derivativeCheck(@LogisticLoss,wTest,order,2,X,y); 17 | 18 | fprintf('Testing gradient using complex-step derivative...\n'); 19 | derivativeCheck(@LogisticLoss,wTest,order,3,X,y); 20 | 21 | fprintf('\n\n\n'); 22 | pause 23 | 24 | fprintf('Testing Hessian using forward-differencing\n'); 25 | order = 2; 26 | derivativeCheck(@LogisticLoss,wTest,order,1,X,y); 27 | 28 | fprintf('Testing Hessian using central-differencing\n'); 29 | order = 2; 30 | derivativeCheck(@LogisticLoss,wTest,order,2,X,y); 31 | 32 | fprintf('Testing Hessian using complex-step derivative\n'); 33 | order = 2; 34 | derivativeCheck(@LogisticLoss,wTest,order,3,X,y); 35 | 36 | fprintf('\n\n\n'); 37 | pause 38 | 39 | fprintf('Testing gradient using fastDerivativeCheck...\n'); 40 | order = 1; 41 | fastDerivativeCheck(@LogisticLoss,wTest,order,1,X,y); 42 | fastDerivativeCheck(@LogisticLoss,wTest,order,2,X,y); 43 | fastDerivativeCheck(@LogisticLoss,wTest,order,3,X,y); 44 | 45 | fprintf('\n\n\n'); 46 | pause 47 | 48 | fprintf('Testing Hessian using fastDerivativeCheck...\n'); 49 | order = 2; 50 | fastDerivativeCheck(@LogisticLoss,wTest,order,1,X,y); 51 | fastDerivativeCheck(@LogisticLoss,wTest,order,2,X,y); 52 | fastDerivativeCheck(@LogisticLoss,wTest,order,3,X,y); 53 | -------------------------------------------------------------------------------- /mil/minFunc_2012/logisticExample/LogisticDiagPrecond.m: -------------------------------------------------------------------------------- 1 | function [m] = LogisticHv(v,w,X,y) 2 | % v(feature,1) - vector that we will apply diagonal preconditioner to 3 | % w(feature,1) 4 | % X(instance,feature) 5 | % y(instance,1) 6 | 7 | sig = 1./(1+exp(-y.*(X*w))); 8 | 9 | % Compute diagonals of Hessian 10 | sig = sig.*(1-sig); 11 | for i = 1:length(w) 12 | h(i,1) = (sig.*X(:,i))'*X(:,i); 13 | end 14 | 15 | % Apply preconditioner 16 | m = v./h; 17 | 18 | % Exact preconditioner 19 | %H = X'*diag(sig.*(1-sig))*X; 20 | %m = H\v; 21 | -------------------------------------------------------------------------------- /mil/minFunc_2012/logisticExample/LogisticHv.m: -------------------------------------------------------------------------------- 1 | function [Hv] = LogisticHv(v,w,X,y) 2 | % v(feature,1) - vector that we will multiply Hessian by 3 | % w(feature,1) 4 | % X(instance,feature) 5 | % y(instance,1) 6 | 7 | sig = 1./(1+exp(-y.*(X*w))); 8 | Hv = X.'*(sig.*(1-sig).*(X*v)); 9 | -------------------------------------------------------------------------------- /mil/minFunc_2012/logisticExample/LogisticLoss.m: -------------------------------------------------------------------------------- 1 | function [nll,g,H,T] = LogisticLoss(w,X,y) 2 | % w(feature,1) 3 | % X(instance,feature) 4 | % y(instance,1) 5 | 6 | [n,p] = size(X); 7 | 8 | Xw = X*w; 9 | yXw = y.*Xw; 10 | 11 | nll = sum(mylogsumexp([zeros(n,1) -yXw])); 12 | 13 | if nargout > 1 14 | if nargout > 2 15 | sig = 1./(1+exp(-yXw)); 16 | g = -X.'*(y.*(1-sig)); 17 | else 18 | %g = -X.'*(y./(1+exp(yXw))); 19 | g = -(X.'*(y./(1+exp(yXw)))); 20 | end 21 | end 22 | 23 | if nargout > 2 24 | H = X.'*diag(sparse(sig.*(1-sig)))*X; 25 | end 26 | 27 | if nargout > 3 28 | T = zeros(p,p,p); 29 | for j1 = 1:p 30 | for j2 = 1:p 31 | for j3 = 1:p 32 | T(j1,j2,j3) = sum(y(:).^3.*X(:,j1).*X(:,j2).*X(:,j3).*sig.*(1-sig).*(1-2*sig)); 33 | end 34 | end 35 | end 36 | end -------------------------------------------------------------------------------- /mil/minFunc_2012/logisticExample/mylogsumexp.m: -------------------------------------------------------------------------------- 1 | function lse = mylogsumexp(b) 2 | % does logsumexp across columns 3 | B = max(b,[],2); 4 | lse = log(sum(exp(b-repmat(B,[1 size(b,2)])),2))+B; 5 | 6 | % Old version that used repmatC 7 | %lse = log(sum(exp(b-repmatC(B,[1 size(b,2)])),2))+B; 8 | end -------------------------------------------------------------------------------- /mil/minFunc_2012/mexAll.m: -------------------------------------------------------------------------------- 1 | % minFunc 2 | fprintf('Compiling minFunc files...\n'); 3 | mex -outdir minFunc/compiled minFunc/mex/mcholC.c 4 | mex -outdir minFunc/compiled minFunc/mex/lbfgsC.c 5 | mex -outdir minFunc/compiled minFunc/mex/lbfgsAddC.c 6 | mex -outdir minFunc/compiled minFunc/mex/lbfgsProdC.c 7 | 8 | -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/lbfgsAddC.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/lbfgsAddC.mexa64 -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/lbfgsAddC.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/lbfgsAddC.mexmaci64 -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/lbfgsAddC.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/lbfgsAddC.mexw64 -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/lbfgsC.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/lbfgsC.mexa64 -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/lbfgsC.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/lbfgsC.mexglx -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/lbfgsC.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/lbfgsC.mexmac -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/lbfgsC.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/lbfgsC.mexmaci -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/lbfgsC.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/lbfgsC.mexmaci64 -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/lbfgsC.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/lbfgsC.mexw32 -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/lbfgsC.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/lbfgsC.mexw64 -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/lbfgsProdC.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/lbfgsProdC.mexa64 -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/lbfgsProdC.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/lbfgsProdC.mexmaci64 -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/lbfgsProdC.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/lbfgsProdC.mexw64 -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/mcholC.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/mcholC.mexa64 -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/mcholC.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/mcholC.mexglx -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/mcholC.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/mcholC.mexmac -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/mcholC.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/mcholC.mexmaci64 -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/mcholC.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/mcholC.mexw32 -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/compiled/mcholC.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/minFunc_2012/minFunc/compiled/mcholC.mexw64 -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/dampedUpdate.m: -------------------------------------------------------------------------------- 1 | function [old_dirs,old_stps,Hdiag,Bcompact] = lbfgsUpdate(y,s,corrections,debug,old_dirs,old_stps,Hdiag) 2 | 3 | %B0 = eye(length(y))/Hdiag; 4 | S = old_dirs(:,2:end); 5 | Y = old_stps(:,2:end); 6 | k = size(Y,2); 7 | L = zeros(k); 8 | for j = 1:k 9 | for i = j+1:k 10 | L(i,j) = S(:,i)'*Y(:,j); 11 | end 12 | end 13 | D = diag(diag(S'*Y)); 14 | N = [S/Hdiag Y]; 15 | M = [S'*S/Hdiag L;L' -D]; 16 | 17 | ys = y'*s; 18 | Bs = s/Hdiag - N*(M\(N'*s)); % Product B*s 19 | sBs = s'*Bs; 20 | 21 | eta = .02; 22 | if ys < eta*sBs 23 | if debug 24 | fprintf('Damped Update\n'); 25 | end 26 | theta = min(max(0,((1-eta)*sBs)/(sBs - ys)),1); 27 | y = theta*y + (1-theta)*Bs; 28 | end 29 | 30 | 31 | numCorrections = size(old_dirs,2); 32 | if numCorrections < corrections 33 | % Full Update 34 | old_dirs(:,numCorrections+1) = s; 35 | old_stps(:,numCorrections+1) = y; 36 | else 37 | % Limited-Memory Update 38 | old_dirs = [old_dirs(:,2:corrections) s]; 39 | old_stps = [old_stps(:,2:corrections) y]; 40 | end 41 | 42 | % Update scale of initial Hessian approximation 43 | Hdiag = (y'*s)/(y'*y); -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/isLegal.m: -------------------------------------------------------------------------------- 1 | function [legal] = isLegal(v) 2 | legal = sum(any(imag(v(:))))==0 & sum(isnan(v(:)))==0 & sum(isinf(v(:)))==0; -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/lbfgs.m: -------------------------------------------------------------------------------- 1 | function [d] = lbfgs(g,s,y,Hdiag) 2 | % BFGS Search Direction 3 | % 4 | % This function returns the (L-BFGS) approximate inverse Hessian, 5 | % multiplied by the gradient 6 | % 7 | % If you pass in all previous directions/sizes, it will be the same as full BFGS 8 | % If you truncate to the k most recent directions/sizes, it will be L-BFGS 9 | % 10 | % s - previous search directions (p by k) 11 | % y - previous step sizes (p by k) 12 | % g - gradient (p by 1) 13 | % Hdiag - value of initial Hessian diagonal elements (scalar) 14 | 15 | [p,k] = size(s); 16 | 17 | for i = 1:k 18 | ro(i,1) = 1/(y(:,i)'*s(:,i)); 19 | end 20 | 21 | q = zeros(p,k+1); 22 | r = zeros(p,k+1); 23 | al =zeros(k,1); 24 | be =zeros(k,1); 25 | 26 | q(:,k+1) = g; 27 | 28 | for i = k:-1:1 29 | al(i) = ro(i)*s(:,i)'*q(:,i+1); 30 | q(:,i) = q(:,i+1)-al(i)*y(:,i); 31 | end 32 | 33 | % Multiply by Initial Hessian 34 | r(:,1) = Hdiag*q(:,1); 35 | 36 | for i = 1:k 37 | be(i) = ro(i)*y(:,i)'*r(:,i); 38 | r(:,i+1) = r(:,i) + s(:,i)*(al(i)-be(i)); 39 | end 40 | d=r(:,k+1); -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/lbfgsAdd.m: -------------------------------------------------------------------------------- 1 | function [S,Y,YS,lbfgs_start,lbfgs_end,Hdiag,skipped] = lbfgsAdd(y,s,S,Y,YS,lbfgs_start,lbfgs_end,Hdiag,useMex) 2 | ys = y'*s; 3 | skipped = 0; 4 | corrections = size(S,2); 5 | if ys > 1e-10 6 | if lbfgs_end < corrections 7 | lbfgs_end = lbfgs_end+1; 8 | if lbfgs_start ~= 1 9 | if lbfgs_start == corrections 10 | lbfgs_start = 1; 11 | else 12 | lbfgs_start = lbfgs_start+1; 13 | end 14 | end 15 | else 16 | lbfgs_start = min(2,corrections); 17 | lbfgs_end = 1; 18 | end 19 | 20 | if useMex 21 | lbfgsAddC(y,s,Y,S,ys,int32(lbfgs_end)); 22 | else 23 | S(:,lbfgs_end) = s; 24 | Y(:,lbfgs_end) = y; 25 | end 26 | YS(lbfgs_end) = ys; 27 | 28 | % Update scale of initial Hessian approximation 29 | Hdiag = ys/(y'*y); 30 | else 31 | skipped = 1; 32 | end -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/lbfgsProd.m: -------------------------------------------------------------------------------- 1 | function [d] = lbfgsProd(g,S,Y,YS,lbfgs_start,lbfgs_end,Hdiag) 2 | % BFGS Search Direction 3 | % 4 | % This function returns the (L-BFGS) approximate inverse Hessian, 5 | % multiplied by the negative gradient 6 | 7 | % Set up indexing 8 | [nVars,maxCorrections] = size(S); 9 | if lbfgs_start == 1 10 | ind = 1:lbfgs_end; 11 | nCor = lbfgs_end-lbfgs_start+1; 12 | else 13 | ind = [lbfgs_start:maxCorrections 1:lbfgs_end]; 14 | nCor = maxCorrections; 15 | end 16 | al = zeros(nCor,1); 17 | be = zeros(nCor,1); 18 | 19 | d = -g; 20 | for j = 1:length(ind) 21 | i = ind(end-j+1); 22 | al(i) = (S(:,i)'*d)/YS(i); 23 | d = d-al(i)*Y(:,i); 24 | end 25 | 26 | % Multiply by Initial Hessian 27 | d = Hdiag*d; 28 | 29 | for i = ind 30 | be(i) = (Y(:,i)'*d)/YS(i); 31 | d = d + S(:,i)*(al(i)-be(i)); 32 | end 33 | -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/lbfgsUpdate.m: -------------------------------------------------------------------------------- 1 | function [old_dirs,old_stps,Hdiag] = lbfgsUpdate(y,s,corrections,debug,old_dirs,old_stps,Hdiag) 2 | ys = y'*s; 3 | if ys > 1e-10 4 | numCorrections = size(old_dirs,2); 5 | if numCorrections < corrections 6 | % Full Update 7 | old_dirs(:,numCorrections+1) = s; 8 | old_stps(:,numCorrections+1) = y; 9 | else 10 | % Limited-Memory Update 11 | old_dirs = [old_dirs(:,2:corrections) s]; 12 | old_stps = [old_stps(:,2:corrections) y]; 13 | end 14 | 15 | % Update scale of initial Hessian approximation 16 | Hdiag = ys/(y'*y); 17 | else 18 | if debug 19 | fprintf('Skipping Update\n'); 20 | end 21 | end -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/mchol.m: -------------------------------------------------------------------------------- 1 | function [l,d,perm] = mchol(A,mu) 2 | % [l,d,perm] = mchol(A,mu) 3 | % Compute the Gill-Murray modified LDL factorization of A, 4 | 5 | if nargin < 2 6 | mu = 1e-12; 7 | end 8 | 9 | n = size(A,1); 10 | l = eye(n); 11 | d = zeros(n,1); 12 | perm = 1:n; 13 | 14 | for i = 1:n 15 | c(i,i) = A(i,i); 16 | end 17 | 18 | % Compute modification parameters 19 | gamma = max(abs(diag(A))); 20 | xi = max(max(abs(setdiag(A,0)))); 21 | delta = mu*max(gamma+xi,1); 22 | if n > 1 23 | beta = sqrt(max([gamma xi/sqrt(n^2-1) mu])); 24 | else 25 | beta = sqrt(max([gamma mu])); 26 | end 27 | 28 | for j = 1:n 29 | 30 | % Find q that results in Best Permutation with j 31 | [maxVal maxPos] = max(abs(diag(c(j:end,j:end)))); 32 | q = maxPos+j-1; 33 | 34 | % Permute d,c,l,a 35 | d([j q]) = d([q j]); 36 | perm([j q]) = perm([q j]); 37 | c([j q],:) = c([q j],:); 38 | c(:,[j q]) = c(:,[q j]); 39 | l([j q],:) = l([q j],:); 40 | l(:,[j q]) = l(:,[q j]); 41 | A([j q],:) = A([q j],:); 42 | A(:,[j q]) = A(:,[q j]); 43 | 44 | for s = 1:j-1 45 | l(j,s) = c(j,s)/d(s); 46 | end 47 | for i = j+1:n 48 | c(i,j) = A(i,j) - sum(l(j,1:j-1).*c(i,1:j-1)); 49 | end 50 | theta = 0; 51 | if j < n 52 | theta = max(abs(c(j+1:n,j))); 53 | end 54 | d(j) = max([abs(c(j,j)) (theta/beta)^2 delta]); 55 | if j < n 56 | for i = j+1:n 57 | c(i,i) = c(i,i) - (c(i,j)^2)/d(j); 58 | end 59 | end 60 | end -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/mcholinc.m: -------------------------------------------------------------------------------- 1 | function [R,tau] = mcholinc(H,verbose) 2 | % Computes Cholesky of H+tau*I, for suitably large tau that matrix is pd 3 | 4 | p = size(H,1); 5 | 6 | beta = norm(H,'fro'); 7 | if min(diag(H)) > 1e-12 8 | tau = 0; 9 | else 10 | if verbose 11 | fprintf('Small Value on Diagonal, Adjusting Hessian\n'); 12 | end 13 | tau = max(beta/2,1e-12); 14 | end 15 | while 1 16 | [R,posDef] = chol(H+tau*eye(p)); 17 | if posDef == 0 18 | break; 19 | else 20 | if verbose 21 | fprintf('Cholesky Failed, Adjusting Hessian\n'); 22 | end 23 | tau = max(2*tau,beta/2); 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /mil/minFunc_2012/minFunc/mex/lbfgsAddC.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mex.h" 3 | 4 | /* See lbfgsAdd.m for details */ 5 | /* This function will not exit gracefully on bad input! */ 6 | 7 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 8 | { 9 | /* Variable Declarations */ 10 | 11 | double *s,*y,*S, *Y, ys; 12 | int i,j,nVars,lbfgs_end; 13 | 14 | /* Get Input Pointers */ 15 | 16 | y = mxGetPr(prhs[0]); 17 | s = mxGetPr(prhs[1]); 18 | Y = mxGetPr(prhs[2]); 19 | S = mxGetPr(prhs[3]); 20 | ys= mxGetScalar(prhs[4]); 21 | lbfgs_end = (int)mxGetScalar(prhs[5]); 22 | 23 | if (!mxIsClass(prhs[5],"int32")) 24 | mexErrMsgTxt("lbfgs_end must be int32"); 25 | 26 | /* Compute number of variables, maximum number of corrections */ 27 | 28 | nVars = mxGetDimensions(prhs[2])[0]; 29 | 30 | for(j=0;j 1 14 | gd2(t3) = gd2(t3) + T(t1,t2,t3)*d(t1)*d(t2); 15 | end 16 | 17 | if nargout > 2 18 | Hd(t2,t3) = Hd(t2,t3) + T(t1,t2,t3)*d(t1); 19 | end 20 | end 21 | 22 | end 23 | end 24 | 25 | f = f + g'*d + (1/2)*d'*H*d + (1/6)*fd3; 26 | 27 | if nargout > 1 28 | g = g + H*d + (1/2)*gd2; 29 | end 30 | 31 | if nargout > 2 32 | H = H + Hd; 33 | end 34 | 35 | if any(abs(d) > 1e5) 36 | % We want the optimizer to stop if the solution is unbounded 37 | g = zeros(p,1); 38 | end -------------------------------------------------------------------------------- /mil/minFunc_2012/rosenbrock.m: -------------------------------------------------------------------------------- 1 | function [f, df, ddf] = rosenbrock(x); 2 | 3 | % rosenbrock.m This function returns the function value, partial derivatives 4 | % and Hessian of the (general dimension) rosenbrock function, given by: 5 | % 6 | % f(x) = sum_{i=1:D-1} 100*(x(i+1) - x(i)^2)^2 + (1-x(i))^2 7 | % 8 | % where D is the dimension of x. The true minimum is 0 at x = (1 1 ... 1). 9 | % 10 | % Carl Edward Rasmussen, 2001-07-21. 11 | 12 | D = length(x); 13 | f = sum(100*(x(2:D)-x(1:D-1).^2).^2 + (1-x(1:D-1)).^2); 14 | 15 | if nargout > 1 16 | df = zeros(D, 1); 17 | df(1:D-1) = - 400*x(1:D-1).*(x(2:D)-x(1:D-1).^2) - 2*(1-x(1:D-1)); 18 | df(2:D) = df(2:D) + 200*(x(2:D)-x(1:D-1).^2); 19 | end 20 | 21 | if nargout > 2 22 | ddf = zeros(D,D); 23 | ddf(1:D-1,1:D-1) = diag(-400*x(2:D) + 1200*x(1:D-1).^2 + 2); 24 | ddf(2:D,2:D) = ddf(2:D,2:D) + 200*eye(D-1); 25 | ddf = ddf - diag(400*x(1:D-1),1) - diag(400*x(1:D-1),-1); 26 | end 27 | -------------------------------------------------------------------------------- /mil/projsplx/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011, Xiaojing 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the distribution 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /mil/projsplx/projsplx_c_float.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/projsplx/projsplx_c_float.mexa64 -------------------------------------------------------------------------------- /mil/projsplx/projsplx_c_float.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/mil/projsplx/projsplx_c_float.mexmaci64 -------------------------------------------------------------------------------- /mil/xform_feat_custom.m: -------------------------------------------------------------------------------- 1 | function f = xform_feat_custom(f, opts) 2 | 3 | %f = f.^pwr; 4 | %f = bsxfun(@times, f, 1./sqrt(sum(f.^2, 2))); 5 | 6 | %target_norm = 20; 7 | 8 | target_norm = opts.target_norm; 9 | 10 | f = f .* (target_norm / opts.feat_norm_mean); 11 | -------------------------------------------------------------------------------- /output/default/README.md: -------------------------------------------------------------------------------- 1 | 2 | Trained models in the detection adaptation step and test outputs are saved in this directory. 3 | -------------------------------------------------------------------------------- /prepare_for_cls_adapt.m: -------------------------------------------------------------------------------- 1 | % AUTORIGHTS 2 | % --------------------------------------------------------- 3 | % Copyright (c) 2016, Dong Li 4 | % 5 | % This file is part of the WSL code and is available 6 | % under the terms of the MIT License provided in 7 | % LICENSE. Please retain this notice and LICENSE if you use 8 | % this file (or any portion of it) in your project. 9 | % --------------------------------------------------------- 10 | 11 | clear; close all; clc; 12 | voc_init; 13 | classes = VOCopts.classes; 14 | for i = 1:length(classes) 15 | [imlist,flag(:,i)] = textread(sprintf(VOCopts.clsimgsetpath,classes{i},'trainval'),'%s %d'); 16 | end 17 | fid = fopen('train_list.txt','w'); 18 | for i = 1:length(imlist) 19 | for j = 1:length(classes) 20 | if flag(i,j) ~= -1 21 | fprintf(fid, '%s %d\n', sprintf(VOCopts.imgpath,imlist{i}), 2*(j-1)); 22 | else 23 | fprintf(fid, '%s %d\n', sprintf(VOCopts.imgpath,imlist{i}), 2*j-1); 24 | end 25 | end 26 | end 27 | fclose(fid); 28 | -------------------------------------------------------------------------------- /prototxt/cls_adapt_solver.prototxt: -------------------------------------------------------------------------------- 1 | net: "prototxt/cls_adapt_train.prototxt" 2 | base_lr: 0.001 3 | lr_policy: "step" 4 | gamma: 0.1 5 | stepsize: 10000 6 | display: 100 7 | max_iter: 10000 8 | momentum: 0.9 9 | weight_decay: 0.0005 10 | snapshot: 10000 11 | snapshot_prefix: "caffenet_cls_adapt" 12 | -------------------------------------------------------------------------------- /prototxt/det_adapt_solver.prototxt: -------------------------------------------------------------------------------- 1 | train_net: "prototxt/det_adapt_train.prototxt" 2 | base_lr: 0.001 3 | lr_policy: "step" 4 | gamma: 0.1 5 | stepsize: 30000 6 | display: 20 7 | average_loss: 100 8 | momentum: 0.9 9 | weight_decay: 0.0005 10 | # We disable standard caffe solver snapshotting and implement our own snapshot 11 | # function 12 | snapshot: 0 13 | # We still use the snapshot prefix, though 14 | snapshot_prefix: "caffenet_det_adapt" 15 | #debug_info: true 16 | -------------------------------------------------------------------------------- /startup.m: -------------------------------------------------------------------------------- 1 | addpath(genpath([cd '/edgebox'])); 2 | addpath([cd '/imdb']); 3 | addpath([cd '/vis/pool5-explorer']); 4 | addpath([cd '/vis']); 5 | addpath([cd '/utils']); 6 | addpath([cd '/features']); 7 | addpath([cd '/mil']); 8 | addpath([cd '/caffe-wsl/matlab/caffe']); 9 | 10 | fprintf('WSL startup done\n'); -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | python ./tools/test_net.py --gpu 0 --def prototxt/test.prototxt --net output/default/voc_2007_trainval/caffenet_det_adapt_iter_40000.caffemodel 2>&1 | tee log_test.txt 2 | -------------------------------------------------------------------------------- /tools/extra/_init_paths.py: -------------------------------------------------------------------------------- 1 | # AUTORIGHTS 2 | # --------------------------------------------------------- 3 | # Copyright (c) 2014, Microsoft 4 | # Copyright (c) 2016, Dong Li 5 | # 6 | # This file is part of the WSL code and is available 7 | # under the terms of the MIT License provided in 8 | # LICENSE. Please retain this notice and LICENSE if you use 9 | # this file (or any portion of it) in your project. 10 | # --------------------------------------------------------- 11 | 12 | """Set up paths for Fast R-CNN.""" 13 | 14 | import os.path as osp 15 | import sys 16 | 17 | def add_path(path): 18 | if path not in sys.path: 19 | sys.path.insert(0, path) 20 | 21 | this_dir = osp.dirname(__file__) 22 | 23 | # Add caffe to PYTHONPATH 24 | caffe_path = osp.join(this_dir, '..', 'caffe-wsl', 'python') 25 | add_path(caffe_path) 26 | 27 | # Add lib to PYTHONPATH 28 | lib_path = osp.join(this_dir, '..', 'lib') 29 | add_path(lib_path) 30 | -------------------------------------------------------------------------------- /tools/extra/_init_paths.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbhuang0604/WSL/470f1cc8e042d0f493a197558c466988d259f27a/tools/extra/_init_paths.pyc -------------------------------------------------------------------------------- /utils/boxoverlap.m: -------------------------------------------------------------------------------- 1 | function o = boxoverlap(a, b) 2 | % Compute the symmetric intersection over union overlap between a set of 3 | % bounding boxes in a and a single bounding box in b. 4 | % 5 | % a a matrix where each row specifies a bounding box 6 | % b a single bounding box 7 | 8 | % AUTORIGHTS 9 | % ------------------------------------------------------- 10 | % Copyright (C) 2011-2012 Ross Girshick 11 | % Copyright (C) 2008, 2009, 2010 Pedro Felzenszwalb, Ross Girshick 12 | % 13 | % This file is part of the voc-releaseX code 14 | % (http://people.cs.uchicago.edu/~rbg/latent/) 15 | % and is available under the terms of an MIT-like license 16 | % provided in COPYING. Please retain this notice and 17 | % COPYING if you use this file (or a portion of it) in 18 | % your project. 19 | % ------------------------------------------------------- 20 | 21 | x1 = max(a(:,1), b(1)); 22 | y1 = max(a(:,2), b(2)); 23 | x2 = min(a(:,3), b(3)); 24 | y2 = min(a(:,4), b(4)); 25 | 26 | w = x2-x1+1; 27 | h = y2-y1+1; 28 | inter = w.*h; 29 | aarea = (a(:,3)-a(:,1)+1) .* (a(:,4)-a(:,2)+1); 30 | barea = (b(3)-b(1)+1) * (b(4)-b(2)+1); 31 | % intersection over union overlap 32 | o = inter ./ (aarea+barea-inter); 33 | % set invalid entries to 0 overlap 34 | o(w <= 0) = 0; 35 | o(h <= 0) = 0; 36 | -------------------------------------------------------------------------------- /utils/cmp_feat_caches.m: -------------------------------------------------------------------------------- 1 | function cmp_feat_caches(dir1, dir2) 2 | % For comparing new feat cache files to known good 3 | % feat cache files after some change 4 | 5 | s = dir([dir1 '/*.mat']); 6 | 7 | for i = 1:length(s) 8 | [a,b,c] = fileparts(s(i).name); 9 | s1 = [dir1 '/' s(i).name]; 10 | s2 = [dir2 '/' b '.mat']; 11 | if ~exist(s2) 12 | fprintf('Skipping %s\n', s(i).name); 13 | continue; 14 | end 15 | 16 | d1 = load(s1); 17 | d2 = load(s2); 18 | 19 | % gt: [2448x1 logical] 20 | % overlap: [2448x20 single] 21 | % boxes: [2448x4 single] 22 | % feat: [2448x9216 single] 23 | % class: [2448x1 uint8] 24 | 25 | assert(sum(abs(d1.gt - d2.gt)) == 0); 26 | assert(sum(sum(abs(d1.overlap - d2.overlap))) == 0); 27 | assert(sum(sum(abs(d1.boxes - d2.boxes))) == 0); 28 | assert(sum(sum(abs(d1.feat - d2.feat))) == 0); 29 | assert(sum(abs(d1.class - d2.class)) == 0); 30 | 31 | fprintf('%d is ok\n', i); 32 | end 33 | -------------------------------------------------------------------------------- /utils/create_folds.m: -------------------------------------------------------------------------------- 1 | function folds = create_folds(N, k_folds) 2 | 3 | prev_rng = seed_rand(); 4 | 5 | perm = randperm(N); 6 | fold_points = floor(linspace(1, N, k_folds+1)); 7 | fold_points(end) = N+1; 8 | folds = cell(k_folds, 1); 9 | for i = 1:k_folds 10 | folds{i} = perm(fold_points(i):fold_points(i+1)-1); 11 | end 12 | assert(isempty(setdiff(1:N, cat(2, folds{:})))); 13 | 14 | rng(prev_rng); 15 | -------------------------------------------------------------------------------- /utils/fc8_model.m: -------------------------------------------------------------------------------- 1 | function rcnn_model = fc8_model(rcnn_model) 2 | 3 | opts.net_def_file = './model-defs/pascal_finetune_deploy.prototxt'; 4 | 5 | rcnn_model.cnn.init_key = ... 6 | caffe('init', opts.net_def_file, rcnn_model.cnn.binary_file); 7 | caffe('set_phase_test'); 8 | rcnn_model.cnn.layers = caffe('get_weights'); 9 | 10 | rcnn_model.detectors.W = rcnn_model.cnn.layers(8).weights{1}; 11 | rcnn_model.detectors.B = rcnn_model.cnn.layers(8).weights{2}'; 12 | -------------------------------------------------------------------------------- /utils/hdf5_dir_to_mat_dir.m: -------------------------------------------------------------------------------- 1 | function [] = hdf5_dir_to_mat_dir(hdf5_dir_path, mat_dir_path, quiet, skip_done) 2 | assert(logical(exist(hdf5_dir_path, 'dir'))); 3 | if ~exist('quiet', 'var') 4 | quiet = false; 5 | end 6 | if ~exist('skip_done', 'var') 7 | skip_done = true; 8 | end 9 | if ~exist(mat_dir_path, 'dir') 10 | mkdir(mat_dir_path); 11 | end 12 | files = dir(sprintf('%s/*.hdf5', hdf5_dir_path)); 13 | parfor i = 1:length(files) 14 | [~, name, ~] = fileparts(files(i).name); 15 | hdf5_path = sprintf('%s/%s.hdf5', hdf5_dir_path, name); 16 | mat_path = sprintf('%s/%s.mat', mat_dir_path, name); 17 | if exist(mat_path, 'file') && skip_done 18 | continue; 19 | end 20 | hdf5_to_mat(hdf5_path, mat_path); 21 | if ~quiet 22 | fprintf('(%d/%d) Converted %s to %s\n', i, length(files), hdf5_path, mat_path); 23 | end 24 | end 25 | end 26 | 27 | function [] = hdf5_to_mat(hdf5_path, mat_path) 28 | x = hdf5_to_struct(hdf5_path); 29 | save(mat_path, '-struct', 'x'); 30 | end 31 | 32 | function x = hdf5_to_struct(hdf5_path) 33 | x.dataset = h5read(hdf5_path, '/dataset'); 34 | x.dataset = x.dataset{1}; 35 | x.gt = h5read(hdf5_path, '/gt'); 36 | x.class = h5read(hdf5_path, '/class'); 37 | x.flip = h5read(hdf5_path, '/flip'); 38 | x.overlap = h5read(hdf5_path, '/overlap')'; 39 | x.boxes = h5read(hdf5_path, '/boxes')'; 40 | x.imagename = h5read(hdf5_path, '/imagename'); 41 | x.imagename = x.imagename{1}; 42 | x.feat = h5read(hdf5_path, '/feat')'; 43 | end 44 | -------------------------------------------------------------------------------- /utils/link_train_val.m: -------------------------------------------------------------------------------- 1 | function link_train_val(varargin) 2 | 3 | ip = inputParser; 4 | ip.addParamValue('year', @isstr); 5 | ip.addParamValue('basedir', @isstr); 6 | 7 | ip.parse(varargin{:}); 8 | opts = ip.Results; 9 | 10 | conf = voc_config('pascal.year', opts.year); 11 | VOCopts = conf.pascal.VOCopts; 12 | 13 | 14 | start_dir = pwd; 15 | cd(opts.basedir); 16 | fprintf('switched to %s\n', pwd); 17 | 18 | sets = {'train', 'val'}; 19 | 20 | for i = 1:length(sets) 21 | system(['mkdir ' sets{i}]); 22 | cd(sets{i}); 23 | fprintf('switched to %s\n', pwd); 24 | image_ids = textread(sprintf(VOCopts.imgsetpath, sets{i}), '%s'); 25 | for j = 1:length(image_ids) 26 | cmd = sprintf('ln -s ../trainval/%s.mat %s.mat', image_ids{j}, image_ids{j}); 27 | fprintf([cmd '\n']); 28 | system(cmd); 29 | end 30 | cd('..'); 31 | fprintf('switched to %s\n', pwd); 32 | end 33 | 34 | cd(start_dir); 35 | fprintf('switched to %s\n', pwd); 36 | -------------------------------------------------------------------------------- /utils/load_h5.m: -------------------------------------------------------------------------------- 1 | function d = load_h5(file_path) 2 | 3 | file_path = [file_path '.hdf5']; 4 | 5 | fid = H5F.open(file_path); 6 | 7 | did = H5D.open(fid, 'dataset'); 8 | d.dataset = H5D.read(did); 9 | d.dataset = d.dataset{1}; 10 | H5D.close(did); 11 | 12 | did = H5D.open(fid, 'gt'); 13 | d.gt = H5D.read(did); 14 | H5D.close(did); 15 | 16 | did = H5D.open(fid, 'class'); 17 | d.class = H5D.read(did); 18 | H5D.close(did); 19 | 20 | did = H5D.open(fid, 'flip'); 21 | d.flip = H5D.read(did); 22 | H5D.close(did); 23 | 24 | did = H5D.open(fid, 'overlap'); 25 | d.overlap = H5D.read(did)'; 26 | H5D.close(did); 27 | 28 | did = H5D.open(fid, 'boxes'); 29 | d.boxes = H5D.read(did)'; 30 | H5D.close(did); 31 | 32 | did = H5D.open(fid, 'imagename'); 33 | d.imagename = H5D.read(did); 34 | d.imagename = d.imagename{1}; 35 | H5D.close(did); 36 | 37 | did = H5D.open(fid, 'feat'); 38 | d.feat = H5D.read(did)'; 39 | H5D.close(did); 40 | 41 | H5F.close(fid); 42 | 43 | % hdf5_path = file_path; 44 | % d.dataset = h5read(hdf5_path, '/dataset'); 45 | % d.dataset = d.dataset{1}; 46 | % d.gt = h5read(hdf5_path, '/gt'); 47 | % d.class = h5read(hdf5_path, '/class'); 48 | % d.flip = h5read(hdf5_path, '/flip'); 49 | % d.overlap = h5read(hdf5_path, '/overlap')'; 50 | % d.boxes = h5read(hdf5_path, '/boxes')'; 51 | % d.imagename = h5read(hdf5_path, '/imagename'); 52 | % d.imagename = d.imagename{1}; 53 | % d.feat = h5read(hdf5_path, '/feat')'; 54 | -------------------------------------------------------------------------------- /utils/mkdir_if_missing.m: -------------------------------------------------------------------------------- 1 | function made = mkdir_if_missing(path) 2 | made = false; 3 | if exist(path) == 0 4 | unix(['mkdir -p ' path]); 5 | made = true; 6 | end 7 | -------------------------------------------------------------------------------- /utils/nms.m: -------------------------------------------------------------------------------- 1 | function pick = nms(boxes, overlap) 2 | % top = nms(boxes, overlap) 3 | % Non-maximum suppression. (FAST VERSION) 4 | % Greedily select high-scoring detections and skip detections 5 | % that are significantly covered by a previously selected 6 | % detection. 7 | % 8 | % NOTE: This is adapted from Pedro Felzenszwalb's version (nms.m), 9 | % but an inner loop has been eliminated to significantly speed it 10 | % up in the case of a large number of boxes 11 | 12 | % Copyright (C) 2011-12 by Tomasz Malisiewicz 13 | % All rights reserved. 14 | % 15 | % This file is part of the Exemplar-SVM library and is made 16 | % available under the terms of the MIT license (see COPYING file). 17 | % Project homepage: https://github.com/quantombone/exemplarsvm 18 | 19 | 20 | if isempty(boxes) 21 | pick = []; 22 | return; 23 | end 24 | 25 | x1 = boxes(:,1); 26 | y1 = boxes(:,2); 27 | x2 = boxes(:,3); 28 | y2 = boxes(:,4); 29 | s = boxes(:,end); 30 | 31 | area = (x2-x1+1) .* (y2-y1+1); 32 | [vals, I] = sort(s); 33 | 34 | pick = s*0; 35 | counter = 1; 36 | while ~isempty(I) 37 | last = length(I); 38 | i = I(last); 39 | pick(counter) = i; 40 | counter = counter + 1; 41 | 42 | xx1 = max(x1(i), x1(I(1:last-1))); 43 | yy1 = max(y1(i), y1(I(1:last-1))); 44 | xx2 = min(x2(i), x2(I(1:last-1))); 45 | yy2 = min(y2(i), y2(I(1:last-1))); 46 | 47 | w = max(0.0, xx2-xx1+1); 48 | h = max(0.0, yy2-yy1+1); 49 | 50 | inter = w.*h; 51 | o = inter ./ (area(i) + area(I(1:last-1)) - inter); 52 | 53 | I = I(find(o<=overlap)); 54 | end 55 | 56 | pick = pick(1:(counter-1)); 57 | -------------------------------------------------------------------------------- /utils/procid.m: -------------------------------------------------------------------------------- 1 | function s = procid() 2 | % Returns a string identifying the process. 3 | 4 | % AUTORIGHTS 5 | % ------------------------------------------------------- 6 | % Copyright (C) 2009-2012 Ross Girshick 7 | % 8 | % This file is part of the voc-releaseX code 9 | % (http://people.cs.uchicago.edu/~rbg/latent/) 10 | % and is available under the terms of an MIT-like license 11 | % provided in COPYING. Please retain this notice and 12 | % COPYING if you use this file (or a portion of it) in 13 | % your project. 14 | % ------------------------------------------------------- 15 | 16 | d = pwd(); 17 | i = strfind(d, '/'); 18 | d = d(i(end)+1:end); 19 | s = d; 20 | -------------------------------------------------------------------------------- /utils/receptive_field_size.m: -------------------------------------------------------------------------------- 1 | function out = receptive_field_size() 2 | 3 | % conv1 11 55x55 4 | % conv2 27 55x55 5 | % pool2 35 27x27 6 | % conv3 51 27x27 7 | % pool3 67 13x13 8 | % conv4 99 13x13 9 | % conv5 131 13x13 10 | % pool5 163 6x6 11 | 12 | out = ... 13 | pool3_to_conv3(... 14 | conv4_to_pool3(... 15 | conv5_to_conv4(... 16 | pool5_to_conv5(1)))); 17 | 18 | return 19 | 20 | out = ... 21 | conv1_to_input(... 22 | conv2_to_conv1(... 23 | pool2_to_conv2(... 24 | conv3_to_pool2(... 25 | pool3_to_conv3(... 26 | conv4_to_pool3(... 27 | conv5_to_conv4(... 28 | pool5_to_conv5(1)))))))); 29 | 30 | function out = pool5_to_conv5(p) 31 | out = 2*(p-1)+1 + 2*floor(3/2); 32 | 33 | function out = conv5_to_conv4(p) 34 | out = 1*(p-1)+1 + 2*floor(3/2); 35 | 36 | function out = conv4_to_pool3(p) 37 | out = 1*(p-1)+1 + 2*floor(3/2); 38 | 39 | function out = pool3_to_conv3(p) 40 | out = 2*(p-1)+1 + 2*floor(3/2); 41 | 42 | function out = conv3_to_pool2(p) 43 | out = 1*(p-1)+1 + 2*floor(3/2); 44 | 45 | function out = pool2_to_conv2(p) 46 | out = 2*(p-1)+1 + 2*floor(3/2); 47 | 48 | function out = conv2_to_conv1(p) 49 | out = 1*(p-1)+1 + 2*floor(5/2); 50 | 51 | function out = conv1_to_input(p) 52 | out = 4*(p-1)+1 + 2*floor(11/2); 53 | -------------------------------------------------------------------------------- /utils/seed_rand.m: -------------------------------------------------------------------------------- 1 | function prev_rng = seed_rand() 2 | % seed_rand - Set random number generator to a fixed seed. 3 | % prev_rng = seed_rand(seed) 4 | % 5 | % Strategic use ensures that results are reproducible. 6 | % 7 | % To restore the previous rng after calling this do: 8 | % rng(prev_rng); 9 | 10 | % AUTORIGHTS 11 | % --------------------------------------------------------- 12 | % Copyright (c) 2014, Ross Girshick 13 | % 14 | % This file is part of the R-CNN code and is available 15 | % under the terms of the Simplified BSD License provided in 16 | % LICENSE. Please retain this notice and LICENSE if you use 17 | % this file (or any portion of it) in your project. 18 | % --------------------------------------------------------- 19 | 20 | % This value works best for me. 21 | seed = 3; 22 | % Just kidding, of course ;-). 23 | 24 | prev_rng = rng; 25 | rng(seed, 'twister') 26 | -------------------------------------------------------------------------------- /utils/test_2010_from_2012.m: -------------------------------------------------------------------------------- 1 | function test_2010_from_2012() 2 | 3 | year = '2010'; 4 | testset = 'test'; 5 | 6 | VOCdevkit2012 = './datasets/VOCdevkit2012'; 7 | VOCdevkit2010 = './datasets/VOCdevkit2010'; 8 | 9 | imdb_2012 = imdb_from_voc(VOCdevkit2012, 'test', '2012'); 10 | 11 | image_ids_2010 = get_2010_test_image_ids(); 12 | detrespath_2010 = '/work4/rbg/VOC2010/VOCdevkit/results/VOC2010/Main/%s_det_test_%s.txt'; 13 | detrespath_2012 = imdb_2012.details.VOCopts.detrespath; 14 | 15 | map = containers.Map; 16 | for i = 1:length(image_ids_2010) 17 | map(image_ids_2010{i}) = true; 18 | end 19 | 20 | for i = 1:length(imdb_2012.details.VOCopts.classes) 21 | cls = imdb_2012.details.VOCopts.classes{i}; 22 | res_fn = sprintf(detrespath_2012, 'comp4', cls); 23 | 24 | [ids, scores, x1, y1, x2, y2] = textread(res_fn, '%s %f %f %f %f %f'); 25 | 26 | res_fn = sprintf(detrespath_2010, 'comp4', cls); 27 | 28 | % write out detections in PASCAL format and score 29 | fid = fopen(res_fn, 'w'); 30 | for i = 1:length(ids) 31 | if map.isKey(ids{i}) 32 | fprintf(fid, '%s %f %d %d %d %d\n', ids{i}, scores(i), x1(i), y1(i), x2(i), y2(i)); 33 | end 34 | end 35 | fclose(fid); 36 | end 37 | 38 | function ids = get_2010_test_image_ids() 39 | fn = '/work4/rbg/VOC2012/VOCdevkit/VOC2010/ImageSets/Main/test.txt'; 40 | ids = textread(fn, '%s'); 41 | -------------------------------------------------------------------------------- /utils/tic_toc_print.m: -------------------------------------------------------------------------------- 1 | function tic_toc_print(fmt, varargin) 2 | % Print only after 1 second has passed since the last print. 3 | % Arguments are the same as for fprintf. 4 | 5 | % AUTORIGHTS 6 | % ------------------------------------------------------- 7 | % Copyright (C) 2009-2012 Ross Girshick 8 | % 9 | % This file is part of the voc-releaseX code 10 | % (http://people.cs.uchicago.edu/~rbg/latent/) 11 | % and is available under the terms of an MIT-like license 12 | % provided in COPYING. Please retain this notice and 13 | % COPYING if you use this file (or a portion of it) in 14 | % your project. 15 | % ------------------------------------------------------- 16 | 17 | persistent th; 18 | 19 | if isempty(th) 20 | th = tic(); 21 | end 22 | 23 | if toc(th) > 1 24 | fprintf(fmt, varargin{:}); 25 | drawnow; 26 | th = tic(); 27 | end 28 | -------------------------------------------------------------------------------- /utils/xVOCap.m: -------------------------------------------------------------------------------- 1 | function ap = xVOCap(rec,prec) 2 | % From the PASCAL VOC 2011 devkit 3 | 4 | mrec=[0 ; rec ; 1]; 5 | mpre=[0 ; prec ; 0]; 6 | for i=numel(mpre)-1:-1:1 7 | mpre(i)=max(mpre(i),mpre(i+1)); 8 | end 9 | i=find(mrec(2:end)~=mrec(1:end-1))+1; 10 | ap=sum((mrec(i)-mrec(i-1)).*mpre(i)); 11 | -------------------------------------------------------------------------------- /utils/xVOChash_init.m: -------------------------------------------------------------------------------- 1 | function hash = xVOChash_init(strs) 2 | % From the PASCAL VOC 2011 devkit 3 | 4 | hsize=4999; 5 | hash.key=cell(hsize,1); 6 | hash.val=cell(hsize,1); 7 | 8 | for i=1:numel(strs) 9 | s=strs{i}; 10 | h=mod(str2double(s([4 6:end])),hsize)+1; 11 | j=numel(hash.key{h})+1; 12 | hash.key{h}{j}=strs{i}; 13 | hash.val{h}(j)=i; 14 | end 15 | 16 | -------------------------------------------------------------------------------- /utils/xVOChash_lookup.m: -------------------------------------------------------------------------------- 1 | function ind = xVOChash_lookup(hash,s) 2 | % From the PASCAL VOC 2011 devkit 3 | 4 | hsize=numel(hash.key); 5 | h=mod(str2double(s([4 6:end])),hsize)+1; 6 | ind=hash.val{h}(strmatch(s,hash.key{h},'exact')); 7 | -------------------------------------------------------------------------------- /vis/browse_saved_boxes.m: -------------------------------------------------------------------------------- 1 | function browse_saved_boxes(dataset, year) 2 | 3 | conf = voc_config('pascal.year', year); 4 | VOCopts = conf.pascal.VOCopts; 5 | 6 | ids = textread(sprintf(VOCopts.imgsetpath, dataset), '%s'); 7 | 8 | for i = 1:length(ids) 9 | d = load_cached_features(dataset, year, ids{i}); 10 | im = imread(sprintf(VOCopts.imgpath, ids{i})); 11 | for j = 1:size(d.boxes,1) 12 | showboxes(im, d.boxes(j, :)); 13 | title(sprintf('%d %d', d.gt(j), d.class(j))); 14 | pause; 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /vis/pick_feature_pair.m: -------------------------------------------------------------------------------- 1 | function feature_pairs = pick_feature_pair(model, N) 2 | 3 | ovM = get_overlap_matrix(); 4 | feature_pairs = zeros(0, 2); 5 | 6 | [~, w_ord] = sort(model.w, 'descend'); 7 | 8 | for i = 1:N 9 | u1 = w_ord(i); 10 | pos1 = mod(u1-1, 36)+1; 11 | ov = ovM(pos1,:); 12 | ok = repmat((ov < 1/3), [1 256]); 13 | ok(u1-pos1+1:u1-pos1+36) = 0; 14 | w = model.w; 15 | w(~ok) = -inf; 16 | [~, ord] = sort(w, 'descend'); 17 | u2 = ord(1); 18 | feature_pairs = cat(1, feature_pairs, [u1 u2]); 19 | end 20 | 21 | 22 | 23 | function ovM = get_overlap_matrix() 24 | 25 | ovM = zeros(36); 26 | 27 | s = 224/6; 28 | points = round(s/2:s:224); 29 | 30 | for i = 1:36 31 | M = zeros(6,6,256); 32 | M(i) = 1; 33 | M = sum(M, 3)'; 34 | [r,c] = find(M); 35 | r1_1 = max(1, points(r) - 81); 36 | r1_2 = min(224, points(r) + 81); 37 | c1_1 = max(1, points(c) - 81); 38 | c1_2 = min(224, points(c) + 81); 39 | 40 | for j = 1:36 41 | M = zeros(6,6,256); 42 | M(j) = 1; 43 | M = sum(M, 3)'; 44 | [r,c] = find(M); 45 | r2_1 = max(1, points(r) - 81); 46 | r2_2 = min(224, points(r) + 81); 47 | c2_1 = max(1, points(c) - 81); 48 | c2_2 = min(224, points(c) + 81); 49 | 50 | ovM(i,j) = boxoverlap([c1_1 r1_1 c1_2 r1_2], [c2_1 r2_1 c2_2 r2_2]); 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /vis/rank_by_feature_pair.m: -------------------------------------------------------------------------------- 1 | function rank_by_feature_pair(f1, f2, model, dataset, year) 2 | 3 | % take a model 4 | % select highest scoring features 5 | 6 | TOP_K = 1000; 7 | NUM_FEAT = 20; 8 | 9 | conf = voc_config('pascal.year', year); 10 | VOCopts = conf.pascal.VOCopts; 11 | 12 | [ids, cls_label] = textread(sprintf(VOCopts.imgsetpath, [model.class '_' dataset]), '%s %d'); 13 | P = find(cls_label == 1); 14 | N = find(cls_label == -1); 15 | cls_ids = ids(P); 16 | not_cls_ids = ids(N); 17 | ids = textread(sprintf(VOCopts.imgsetpath, dataset), '%s'); 18 | ids = cat(1, not_cls_ids(1:min(length(not_cls_ids), 2*length(cls_ids))), cls_ids); 19 | 20 | % value, ids ind, box ind 21 | top_boxes = zeros(0, 3+4); 22 | 23 | opts.layer = 'pool5'; 24 | opts.fine_tuned = 1; 25 | opts.use_flipped = 0; 26 | 27 | for i = 1:length(ids) 28 | tic_toc_print('%d/%d\n', i, length(ids)); 29 | d = load_cached_features(dataset, year, ids{i}, opts); 30 | 31 | bs = [d.boxes d.feat(:,f1)+d.feat(:,f2)]; 32 | sel = fast_nms(bs, 0.1); 33 | sz = length(sel); 34 | % score, image_ids_index, ignore, box 35 | new_boxes = [d.feat(sel,f1)+d.feat(sel,f2) ones(sz,1)*i (1:sz)' d.boxes(sel,:)]; 36 | 37 | top_boxes = cat(1, top_boxes, new_boxes); 38 | [~, ord] = sort(top_boxes(:,1), 'descend'); 39 | if length(ord) > TOP_K 40 | ord = ord(1:TOP_K); 41 | end 42 | top_boxes = top_boxes(ord,:); 43 | end 44 | 45 | save_file = sprintf('paper-figures/pair_%d_%d_rank_by_feature_ft_%d', ... 46 | f1, f2, opts.fine_tuned); 47 | save(save_file, 'f1', 'f2', 'ids', 'top_boxes', 'VOCopts', 'model'); 48 | -------------------------------------------------------------------------------- /vis/sample_correlated_pairs.m: -------------------------------------------------------------------------------- 1 | function feature_pairs = sample_correlated_pairs(S, N) 2 | 3 | ovM = get_overlap_matrix(); 4 | feature_pairs = zeros(0, 3); 5 | 6 | for i = 1:N 7 | while true 8 | u1 = randi(size(S,1)); 9 | pos1 = mod(u1-1, 36)+1; 10 | ov = ovM(pos1,:); 11 | ok = repmat((ov < 1/3), [1 256]); 12 | ok(u1-pos1+1:u1-pos1+36) = 0; 13 | row = S(u1, :); 14 | row(~ok) = -inf; 15 | [~, ord] = sort(row, 'descend'); 16 | u2 = ord(1); 17 | if S(u1, u2) > 0 18 | feature_pairs = cat(1, feature_pairs, [u1 u2 S(u1, u2)]); 19 | break; 20 | end 21 | end 22 | end 23 | 24 | [~, ord] = sort(feature_pairs(:,3), 'descend'); 25 | feature_pairs = feature_pairs(ord,:); 26 | 27 | 28 | 29 | function ovM = get_overlap_matrix() 30 | 31 | ovM = zeros(36); 32 | 33 | s = 224/6; 34 | points = round(s/2:s:224); 35 | 36 | for i = 1:36 37 | M = zeros(6,6,256); 38 | M(i) = 1; 39 | M = sum(M, 3)'; 40 | [r,c] = find(M); 41 | r1_1 = max(1, points(r) - 81); 42 | r1_2 = min(224, points(r) + 81); 43 | c1_1 = max(1, points(c) - 81); 44 | c1_2 = min(224, points(c) + 81); 45 | 46 | for j = 1:36 47 | M = zeros(6,6,256); 48 | M(j) = 1; 49 | M = sum(M, 3)'; 50 | [r,c] = find(M); 51 | r2_1 = max(1, points(r) - 81); 52 | r2_2 = min(224, points(r) + 81); 53 | c2_1 = max(1, points(c) - 81); 54 | c2_2 = min(224, points(c) + 81); 55 | 56 | ovM(i,j) = boxoverlap([c1_1 r1_1 c1_2 r1_2], [c2_1 r2_1 c2_2 r2_2]); 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /vis/show_detections.m: -------------------------------------------------------------------------------- 1 | function show_detections(model, split, year) 2 | 3 | conf = voc_config('pascal.year', year); 4 | dataset.year = year; 5 | dataset.trainset = split; 6 | dataset.image_ids = textread(sprintf(conf.pascal.VOCopts.imgsetpath, split), '%s'); 7 | show_det(model, dataset, conf); 8 | 9 | % ------------------------------------------------------------------------ 10 | function show_det(model, dataset, conf) 11 | % ------------------------------------------------------------------------ 12 | 13 | for i = 1:length(dataset.image_ids) 14 | tic_toc_print('%s: %d/%d\n', ... 15 | procid(), i, length(dataset.image_ids)); 16 | d = load_cached_features_hos(dataset.trainset, dataset.year, dataset.image_ids{i}, model.opts); 17 | 18 | if isempty(find(d.class == model.class_id)) 19 | continue; 20 | end 21 | 22 | im = imread(sprintf(conf.pascal.VOCopts.imgpath, dataset.image_ids{i})); 23 | % boxes who overlap a gt by > 70% 24 | z = d.feat*model.w + model.b; 25 | 26 | I = find(~d.gt & z > -1); 27 | boxes = cat(2, single(d.boxes(I,:)), z(I)); 28 | [~, ord] = sort(z(I), 'descend'); 29 | ord = ord(1:min(length(ord), 20)); 30 | boxes = boxes(ord, :); 31 | 32 | % nms_interactive(im, boxes, 0.3); 33 | 34 | % keep = 1:size(boxes,1); 35 | keep = nms(boxes, 0.3); 36 | showboxes(im, boxes(keep,1:4)); 37 | pause; 38 | % for k = 1:length(keep) 39 | % showboxes(im, boxes(keep(k),1:4)); 40 | % title(sprintf('score: %.3f\n', boxes(keep(k),end))); 41 | % pause; 42 | % end 43 | end 44 | -------------------------------------------------------------------------------- /vis/showboxes_hos.m: -------------------------------------------------------------------------------- 1 | function showboxes_hos(im, boxes, color, draw, cid, pid) 2 | 3 | if nargin <= 3 4 | draw = true; 5 | end 6 | 7 | %optionally print cid 8 | if nargin <= 4 9 | cid = nan; 10 | end 11 | 12 | if nargin == 5 13 | pid = nan; 14 | end 15 | 16 | % doing this initializes the image. set to false in consequent runs. 17 | % if this function is to be called multiple times on the same image. 18 | if draw 19 | image(im); 20 | axis image; 21 | axis off; 22 | end 23 | 24 | if ~isempty(boxes) 25 | for j = 1:size(boxes,1) 26 | 27 | x1 = boxes(j,1); 28 | y1 = boxes(j,2); 29 | x2 = boxes(j,3); 30 | y2 = boxes(j,4); 31 | 32 | line([x1 x1 x2 x2 x1 x1]', [y1 y2 y2 y1 y1 y2]', 'color', color, ... 33 | 'linewidth', 1); 34 | 35 | if isnan(cid) 36 | text(x1+3, y1+17, num2str(j), 'backgroundcolor', color); 37 | elseif isnan(pid) 38 | text(x1+3, y1+17, ['C', num2str(cid), '_', num2str(j)],... 39 | 'backgroundcolor', color, 'fontsize', 5); 40 | else 41 | text(x1+3, y1+17, ['C', num2str(cid), '_', num2str(pid)],... 42 | 'backgroundcolor', color, 'fontsize', 5); 43 | end 44 | 45 | end 46 | end 47 | drawnow; -------------------------------------------------------------------------------- /vis/vis_test_dets.m: -------------------------------------------------------------------------------- 1 | function vis_test_dets(split, year, cls) 2 | 3 | conf = voc_config('pascal.year', year); 4 | 5 | VOCopts = conf.pascal.VOCopts; 6 | 7 | res_fn = sprintf(VOCopts.detrespath, 'comp4', cls); 8 | 9 | [ids, scores, x1, y1, x2, y2] = textread(res_fn, '%s %f %f %f %f %f'); 10 | 11 | [~, ord] = sort(scores, 'descend'); 12 | 13 | for i = 1:length(ord) 14 | j = ord(i); 15 | 16 | im = imread(sprintf(VOCopts.imgpath, ids{j})); 17 | 18 | showboxes(im, [x1(j) y1(j) x2(j) y2(j)]); 19 | title(num2str(scores(j))); 20 | pause; 21 | end 22 | -------------------------------------------------------------------------------- /voc_init.m: -------------------------------------------------------------------------------- 1 | VOCdevkit = './data/VOCdevkit2007/'; 2 | tmp = pwd; 3 | cd(VOCdevkit); 4 | addpath([cd '/VOCcode']); 5 | VOCinit; 6 | cd(tmp); --------------------------------------------------------------------------------