Code Monkey home page Code Monkey logo

hdc.caffe's Introduction

Hard-Aware-Deeply-Cascaded-Embedding [ICCV2017 (spotlight)]

Congratulations to our work is accepted by ICCV2017 (spotlight).

There exist a typo previously about the initial learning rate of CARS196, 0.001 should be changed to 0.01. The HDC prefers larger learning rates.

Here is the link of the trained models(permitted for NON-COMMERCIAL usage only, if for COMMERCIAL, please contact [email protected])

Drop Box Stanford-Online-Products/CUB-200-2011/CARS196

BaiduYunPan Stanford-Online-Products/CUB-200-2011/CARS196

04/11/2017 Add some tips on how to add new layers to caffe!

Note!!! I found many people do not know how to add new layers to caffe framework. Here is a vivid explainations: First you need to add the "*.hpp *cpp *.cu" to the project. Then you need to edit the caffe.proto. First you need to check the max ID that you have used. Here we will take the caffe.proto as an example. You could check that in the line 407 with the optional WindowDataParameter window_data_param = 129;. So you check in the lines(1169-1200) to know that the WindowDataParameter contains 13 parameters. Therefore, you need to add this line optional PairFastLossParameter pair_fast_loss_param = 143; as 129 + 13 = 142. Besides, you also need to add the the following lines to spercify the parameters of the newly added layers.

   message PairFastLossParameter {
     optional float margin = 1 [default = 1.0];
     optional float hard_ratio = 2 [default = 1.0];
     optional float factor = 3 [default = 10];
     enum MODE {
       POS = 0;
       NEG = 1;
       BOTH = 2;
     }
     optional MODE mode = 4 [default = BOTH];
   }

Update 03/30/2017 Information : The attached models are not well trained for the final test, as there exist some small bugs. We will release all the final single best models as soon as possible ! we fix a bug that the gradient problem for pair_fast_loss_layer !

Information : The weight_decay for CARS196 should be 0.0002, the original version is typed to be 0.0005 !

This repository has the source code for the paper "Hard-Aware-Deeply-Cascaded-Embedding_release". This paper is available on arXiv. For the loss layer implementation, look at the folder caffe_layers.

Citing this work

If you find this work useful in your research, please consider citing :

@article{yuan2016HDC,
  title={Hard-Aware Deeply Cascaded Embedding},
  author={Yuan, Yuhui and Yang, Kuiyuan and Zhang, Chao},
  journal={arXiv preprint arXiv:1611.05720},
  year={2016}
}

Installation

  1. Install Caffe (including the python interface if you want to use the test code)
  2. Add the "NormalizationLayer" and "PairFastLossLayer" to the caffe.

Prerequisites

  1. caffe (python interface)
  2. matplotlib,cPickle,numpy,lmdb
  3. We assumed that you are using Windows (you can rewrite the *.bat to *.sh if you choose Linux or MacOs)

Datasets & Models

  1. Download pretrained GoogLeNet model from here
  2. Download the datasets needed (you could download them from the official sets): StanfordOnlineProducts CARS196 CUB200 DeepFashion (we will release our results on both both in-shop and consumer2shop.)
  3. You should change the path of images in the Training Prototxt.

Usage

Process Data: (you should in the folder /src_code/):

   python hdc_process.py -d stanford_products
   python hdc_process.py -d cub200
   python hdc_process.py -d cars196
   python hdc_process.py -d deepfashion

Training Models: (currently we only support HDC for your convenience)

   python hdc_train.py -d stanford_products -c HDC
   python hdc_train.py -d cub200 -c HDC
   python hdc_train.py -d cars196 -c HDC

You could change the image path in the training prototxt to train the models with bounding boxes or not

Extract Features:

  python hdc_feature.py -d stanford_products -c HDC
  python hdc_feature.py -d cub200 -c HDC
  python hdc_feature.py -d cars196 -c HDC

Test Models:

   python hdc_test.py -d stanford_products -c HDC
   python hdc_test.py -d cub200 -c HDC
   python hdc_test.py -d cars196 -c HDC

Improve Space

To get better results than the paper, you could simply by sampling more batches. For convenience, we all sample for 5000 times. In our experiments, by sampling 10,000 times could further improve the performance.

hdc.caffe's People

Contributors

pkurainbow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hdc.caffe's Issues

How to extract feature

Sorry, i can't extract the feature after traning the model. "../bin/extract_feature.exe" is not found. Can you tell me how to do it?

about the cars data

thanks for your code first.
The Cars dataset contains 16,185 images of 196 classes of cars. The data is split into 8,144 training images and 8,041 testing images
but the code show that:
if choice == 'train': for i in range(0, 8054): cur_str = lines[i] split_str = cur_str.split(' ') image_str = (split_str[0]).split('/') cur_line = image_str[1] + " " + split_str[1] + "\n" file_w.write(cur_line) file_w.close()
it has the 8054?

recall calculation

https://github.com/PkuRainBow/Hard-Aware-Deeply-Cascaded-Embedding_release/blob/e2f5462aab0ed1c9d6a85503bf7d42eac632d5b1/src_code/test_deep_fashion.py#L29

Hi, I was wondering how you calculated the recall. In fact, in your code, if you query K images and once you get one correct, and this is a 100% recall in your code. But as far as I know, recall@K means if you have N images in the gallery corresponding to the anchor and you find M images correct in these K images, the recall@K=M/N and precision=N/K. But in your code, once M is not zero, your recall got to be 1. Can you explain this for me? I'm really confused. Thank you a lot.

Why Recall@K is equal to zero

I try to execute the command " python hdc_test.py -d cars196 -c HDC" using the model trained by you. But
in the script hdc_test.py, when choose HDC method, the function test_cars.eval is called. So it occurs an error. i think test_cars.eval_HDC should be called. I modify the error. In the function eval_HDC, load_lmdb should be given to feature_dim/3(feature_dim=384). After i modify all the errors, the computed recall@K is equal to zero, no matter what's the value of K. I do not know why?


stanford cars mean recall@ 1 : 0.000000
stanford cars mean recall@ 2 : 0.000000
stanford cars mean recall@ 4 : 0.000000
stanford cars mean recall@ 8 : 0.000000
stanford cars mean recall@ 16 : 0.000000
stanford cars mean recall@ 32 : 0.000000

Issues when extracting features

Hi, @PkuRainBow

Thanks for sharing your excellent work, and this repo.
I am trying to do some experiments on inshop retrieval, where HDC demonstrates good results.
I have successfully trained the initial model, and I am stucked at feature extraction step.... It throws the following error message and I hope you could give some advice:

E0927 03:07:58.285436 76256 extract_features.cpp:52] Using GPU
E0927 03:07:58.285890 76256 extract_features.cpp:58] Using Device_id=4
E0927 03:07:59.457636 76256 io.cpp:80] Could not open or find file ../../data/deepfashion/inshop/img/WOMEN/Blouses_Shirts/id_00000001/02_2_side.jpg     0
F0927 03:07:59.457762 76256 image_data_layer.cpp:72] Check failed: cv_img.data Could not load img/WOMEN/Blouses_Shirts/id_00000001/02_2_side.jpg        0

But the image is there:

$ find ../../data/deepfashion/inshop/img/WOMEN/Blouses_Shirts/id_00000001/02_2_side.jpg
../../data/deepfashion/inshop/img/WOMEN/Blouses_Shirts/id_00000001/02_2_side.jpg

And the query.txt shares the same format of hdc_train.txt, which is rather weird.
Any suggestion would be great!
Thank in advance!

P.S:

The data layer in HDC_deploy.prototxt is defined as other HDC_deploy.prototxt under different dataset directory:

layer {
  name: "deepfashion_inshop"
  type: "ImageData"
  top: "data"
  top: "label"
  include{
    phase: TEST
  }
  transform_param {
    crop_size: 224
    mean_value: 104
    mean_value: 117
    mean_value: 123
  }
  image_data_param {
    source: "../../data/deepfashion/inshop/query.txt"
    batch_size: 200  
    new_height: 256
    new_width: 256
    # replace the root_folder with the path to your Stanford_Online_Products dataset
    root_folder: "../../data/deepfashion/inshop/"
  }
}

VehicleID Evaluation

Hi @PkuRainBow , thanks for open sourcing your work. I want to test the PKU-VehicleID dataset with your method but can't find the corresponding instruction or code. Can you help me out?

about the negative sample mining process, cascade or fixed?

I notice that you use the different 'hard_ratio' values in different branches(1.0, 0.5. 0.2) to control the negative sample mining process instead of selecting the failed sample from the previous cascade?

Is this a kind of approximation or I missed something?
Thanks

About the train batch size

My Graphic card is GTX1080. So the batch size in my experiment cannot be set as large as 100. Will it decrease the accuracy?

About test CARS196

Hi,
I have a problem when test CARS196. Would pls. help me?
Traceback (most recent call last):
File "hdc_test.py", line 126, in
main(sys.argv[1:])
File "hdc_test.py", line 55, in main
data_cnt, feature_dim, top_cnt)
File "/export//hardmining/Hard-Aware-Deeply-Cascaded-Embedding_release-master/src_code/test_cars196.py", line 70, in eval_HDC
get_recall(dists, query_label_vector, data_label_vector, top_cnt)
File "/export/
/hardmining/Hard-Aware-Deeply-Cascaded-Embedding_release-master/src_code/test_cars196.py", line 11, in get_recall
labels_sorted = data_label_vector[np.argsort(dists[i, :])].flatten()
TypeError: only integer scalar arrays can be converted to a scalar index

Test result does not match the paper

I checked out your code and ran test on the StanfordOnlineProduct dataset. I used your pre-trained model: StanfordProducts_FastPair_cascade_v1_hard_ratio_iter_60000_50_25_10_672.caffemodel.
The test result is as follows:

stanford online products mean recall@ 1 : 0.450450
stanford online products mean recall@ 10 : 0.685800
stanford online products mean recall@ 100 : 0.785500
stanford online products mean recall@ 1000 : 0.860150

This doesn't seem to match the result in the paper:

HDC + Contrastive 384 69.5 (@1) 84.4(@10) 92.8(@100) 97.7(@1000)

I do find out that the labels in your HDC_train.txt file differ from those in Ebay_train.txt by 1. For example: mug_final/151771651316_1.JPG has label 6687 in Evay_train.txt but has label 6686 in HDC_train.txt. Anyway I don't think that matters because as long as the labels are consistent within the same file it should be fine, not to mention that I am using the pre-trained model so those files were not used at all.

Could you give me some hint on what might have gone wrong so that the test results do not match the paper? Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.