Code Monkey home page Code Monkey logo

unsupervised-person-re-identification-clustering-and-fine-tuning's Introduction

Setup

All our code is implemented in Keras, Tensorflow (Python). Installation instructions are as follows:

pip install --user tensorflow-gpu
pip install --user keras
pip install --user sklearn

Baseline (Fine-tuned ResNet-50)

We provide the fine-tuned models as follows:

  1. Duke 2. Market 3. CUHK03 4. Duke + Market 5. Duke + CUHK03 6. Market + CUHK03

Progressive Unsupervised Learning (PUL)

To reappear Duke -> Market:

  1. Rename the above fine-tuned "Duke" model as "0.ckpt", which is treated as original model for PUL;

  2. Create directory "checkpoint" under the folder "PUL", and move the original model "0.ckpt" into the "checkpoint";

  3. Modify PUL/unsupervised.py or PUL/semi-supervised.py and PUL/evaluate.py to train and evaluate Duke -> Market.

If you find this code useful, consider citing our work:

@article{fan18unsupervisedreid,
  author    = {Hehe Fan and Liang Zheng and Chenggang Yan and Yi Yang},
  title     = {Unsupervised Person Re-identification: Clustering and Fine-tuning},
  journal   = {{ACM} Transactions on Multimedia Computing, Communications, and Applications {TOMM}},
  volume    = {14},
  number    = {4},
  pages     = {83:1--83:18},
  year      = {2018},
  doi       = {10.1145/3243316}
}

unsupervised-person-re-identification-clustering-and-fine-tuning's People

Contributors

hehefan 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  avatar  avatar  avatar

Watchers

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

unsupervised-person-re-identification-clustering-and-fine-tuning's Issues

Queries regarding the Algorithm and Code

I have two doubts : one regarding the algorithm and the second regarding the code

(1) In Algorithm 1, why do u initialize 'w' randomly in every epoch (step 2)? Shouldn't you initialize 'w' once as it is necessary that there should be atleast one sample in every cluster.

(2) In line 125 of "PUL/unsupervised.py", I was wondering why you are loading only the initial pre-trained model. Shouldn't you be loading the previous finetuned model , i.e. the variable init_model = previous_model?

License

Good day @hehefan,

Thanks for the great project! I'm wondering what's the license for the source code?

ValueError: No such layer: avg_pool

I run the train.py and get 0.ckpt,but when I use it to run unsupervised.py,I get the error:
Traceback (most recent call last):
File "unsupervised.py", line 97, in
net = Model(input=previous_model.input, output=previous_model.get_layer('avg_pool').output)
File "/home/zhangkun/anaconda3/envs/tensorflow/lib/python3.6/site-packages/keras/engine/network.py", line 364, in get_layer
raise ValueError('No such layer: ' + name)
ValueError: No such layer: avg_pool

load model

Hi @hehefan,

I got the following message:
.local/lib/python2.7/site-packages/keras/models.py:287: UserWarning: Error in loading the saved optimizer state. As a result, your model is starting with a freshly initialized optimizer.
warnings.warn('Error in loading the saved optimizer '

when running unsupervised.py using fine tuned duke checkpoint

thanks

keras version?

I run the PUL/unsupervised.py and happen the error
'''
/usr/local/lib/python2.7/dist-packages/Keras-2.1.3-py2.7.egg/keras/models.py:291: UserWarning: Error in loading the saved optimizer state. As a result, your model is starting with a freshly initialized optimizer.
semi-supervised.py:95: UserWarning: Update your Model call to the Keras 2 API: Model(outputs=Tensor("av..., inputs=Tensor("in...)
net = Model(input=previous_model.input, output=previous_model.get_layer('avg_pool').output)
'''
what is your keras version?

about evaluate

there are two datesets ,bbox_test and query ,in /baseline/evaluate.py,but i don't konw how to create ,could you teel me ,thanks .

The model loads slowly

load model

net = load_model(model)
net = Model(input=net.input, output=net.get_layer('avg_pool').output)

I wonder why the loading model is slow

How long is process time?? It's very long time. Is it normal??

Hello Sir,

I am testing your code.

At first, I ran train.py in baseline using Duke dataset.
And ran evaluate.py in baseline.
Those were finished.

Then, I started unsupervised.py in PUL using Duke dataset.
I am waiting for 15 hours but this is running K-means clustering.
Is this normal?? (my program is on V100 gpu)

If not, please tell me your processing time of sample-data (ex: Duke).

Thanks.

baseline mAP and Rank 1 always = 0

Hi! Using the baseline available online, i always get mAP = rank 1 = 0.
Am I missing something or I have to train from scratch.
I also have this error
UserWarning: Error in loading the saved optimizer state. As a result, your model is starting with a freshly initialized optimizer.

memory leak issue

As I do clustering and finetuning stages, it seems like that the GPU would have some kind of memory leak after few epoches, say 15.

And the log looks like this:

2017-11-28 04:34:09.669978: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 75 Chunks of size 37632 totalling 2.69MiB
2017-11-28 04:34:09.669990: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 1 Chunks of size 44800 totalling 43.8KiB
2017-11-28 04:34:09.670002: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 17 Chunks of size 60672 totalling 1007.2KiB
2017-11-28 04:34:09.670014: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 544 Chunks of size 65536 totalling 34.00MiB
2017-11-28 04:34:09.670026: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 29 Chunks of size 81920 totalling 2.27MiB
2017-11-28 04:34:09.670038: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 1 Chunks of size 119040 totalling 116.2KiB
2017-11-28 04:34:09.670049: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 1 Chunks of size 122368 totalling 119.5KiB
2017-11-28 04:34:09.670061: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 121 Chunks of size 131072 totalling 15.12MiB
2017-11-28 04:34:09.670073: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 226 Chunks of size 147456 totalling 31.78MiB
2017-11-28 04:34:09.670085: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 1 Chunks of size 163840 totalling 160.0KiB
2017-11-28 04:34:09.670097: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 17 Chunks of size 178688 totalling 2.90MiB
2017-11-28 04:34:09.670109: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 641 Chunks of size 262144 totalling 160.25MiB
2017-11-28 04:34:09.670121: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 1 Chunks of size 263424 totalling 257.2KiB
2017-11-28 04:34:09.670132: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 8 Chunks of size 307712 totalling 2.35MiB
2017-11-28 04:34:09.670144: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 1 Chunks of size 327680 totalling 320.0KiB
2017-11-28 04:34:09.670155: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 212 Chunks of size 524288 totalling 106.00MiB
2017-11-28 04:34:09.670167: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 344 Chunks of size 589824 totalling 193.50MiB
2017-11-28 04:34:09.670179: I tensorflow/core/common_runtime/bfc_allocator.cc:679] 1 Chunks of size 671744 totalling 656.0KiB

Just wondering if you have ever run into this, it reappears every time when i train.

Hope that you can help fix this minor problem.

Thanks,

faster eval

I find the evaluate code running very slow when predict accuracy is low, and manage to accelerate the evaluation.

The key point is, when we get the match and junk array, we can also get the indexes of these person id in result_argsort. With these indexes, we can compute the rank_1 and'mAP' value in a much smaller double cycle.

def map_rank_quick_eval(query_info, test_info, result_argsort):
    # about 10% lower than matlab result
    # for evaluate rank1 and map
    match = []
    junk = []

    for q_index, (qp, qc) in enumerate(query_info):
        tmp_match = []
        tmp_junk = []
        for t_index in range(len(test_info)):
            p_t_idx = result_argsort[q_index][t_index]
            p_info = test_info[int(p_t_idx)]

            tp = p_info[0]
            tc = p_info[1]
            if tp == qp and qc != tc:
                tmp_match.append(t_index)
            elif tp == qp or tp == -1:
                tmp_junk.append(t_index)
        match.append(tmp_match)
        junk.append(tmp_junk)

    rank_1 = 0.0
    mAP = 0.0
    for idx in range(len(query_info)):
        if idx % 100 == 0:
            print('evaluate img %d' % idx)
        recall = 0.0
        precision = 1.0
        ap = 0.0
        YES = match[idx]
        IGNORE = junk[idx]
        ig_cnt = 0
        for ig in IGNORE:
            if ig < YES[0]:
                ig_cnt += 1
            else:
                break
        if ig_cnt >= YES[0]:
            rank_1 += 1

        for i, k in enumerate(YES):
            ig_cnt = 0
            for ig in IGNORE:
                if ig < k:
                    ig_cnt += 1
                else:
                    break
            cnt = k + 1 - ig_cnt
            hit = i + 1
            tmp_recall = hit / len(YES)
            tmp_precision = hit / cnt
            ap = ap + (tmp_recall - recall) * ((precision + tmp_precision) / 2)
            recall = tmp_recall
            precision = tmp_precision

        mAP += ap
    rank1_acc = rank_1 / QUERY_NUM
    mAP = mAP / QUERY_NUM
    print('Rank 1:\t%f' % rank1_acc)
    print('mAP:\t%f' % mAP)
    return rank1_acc, mAP

Although this code can compute rank_1_acc and mAP very fast (in 3 minute) and rank_1_acc is the same with the origin code, but mAP is a little larger than the origin result.

Is there anything wrong with this code?

No such file or directory: '../dataset/Duke/bounding_box_train/0001_c2_f0046182.jpg'

When I run the 'python unsupervised.py'
(kertf) mickey@a208-System-Product-Name:~/Unsupervised-Person-Re-identification-Clustering-and-Fine-tuning/PUL$ python unsupervised.py
/home/mickey/miniconda3/envs/kertf/lib/python3.6/importlib/_bootstrap.py:205: RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6
return f(*args, **kwds)
Using TensorFlow backend.
2019-06-12 21:30:56.332595: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2019-06-12 21:30:56.429239: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:892] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-06-12 21:30:56.429564: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Found device 0 with properties:
name: TITAN Xp major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:01:00.0
totalMemory: 11.90GiB freeMemory: 11.59GiB
2019-06-12 21:30:56.429594: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: TITAN Xp, pci bus id: 0000:01:00.0, compute capability: 6.1)
Traceback (most recent call last):
File "unsupervised.py", line 63, in
img = image.load_img(os.path.join(TRAIN, img), target_size=[224, 224])
File "/home/mickey/.local/lib/python3.6/site-packages/keras_preprocessing/image/utils.py", line 110, in load_img
img = pil_image.open(path)
File "/home/mickey/miniconda3/envs/kertf/lib/python3.6/site-packages/PIL/Image.py", line 2652, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: '../dataset/Duke/bounding_box_train/0001_c2_f0046182.jpg'
The bounding box directory is not found in the dataset.
Can you give me some advice?
Best wishes to you!

How to train your code??

Hello Sir.

I want to try your code.
But I could not know the sequence of your code.

----- the sequence ---------

  1. train /baseline/train.py
  2. ??
  3. ??
  4. ??
  5. ..

Thanks

No Average Pooling Layer in the Model

Traceback (most recent call last):
File "evaluate.py", line 71, in
net = Model(input=net.input, output=net.get_layer('avg_pool').output)
File "/home/pc1/unsuper/local/lib/python2.7/site-packages/keras/engine/network.py", line 364, in get_layer
raise ValueError('No such layer: ' + name)
ValueError: No such layer: avg_pool

@hehefan I have executed your base-line code and its giving the above mentioned error. Please assist as soon as possible.

Request for WHOS feature of DukeMTMC

I'm working on Person reid and want to recurrent UMDL(a paper in CVPR2016, which used WHOS feature) on DukeMTMC-reID dataset. I found this newly published dataset hasn't been collected in Whos github project. Meanwhile, UMDL didn't conduct experiments on DukeMTMC-reID dataset.

But I found transfer result of UMDL in this work. I guess you have implemented UMDL on DukeMTMC and if so, you have WHOS feature for DukeMTMC.

Therefore, can you kindly release WHOS feature in this DukeMTMC-reID repository?

Similarity matrix

Hi, I'm also implementing person re-id in keras and found this repository, but I'm confused about the similarity matrix computation in baseline evaluation code.

Generally, we compute similarities between probe features and gallery features using euclidean distance formula, so the value in the similarity matrix position(i,j) will be (probe[i] - gallery[j]).^2. But in this code. the value in the similarity matrix is two vectors's dot product: probe[i]*gallery[j].

I wonder whether this metric really works. Is there any references about this metric that compute similarity by vectors' dot product?

Parser for CUHK dataset

Hello! Where can we find a parser for CUHK dataset which was used in your implementation and is giving output in format pointed in corresponding .list files (such as 0001_c1_f02.jpg 0). Thak you in advance.

resnet 50

does your resnet50 have trained by imagenet ?
if it dose , are you sure when you use resnet50 (load imagenet weight) to exact features , your resnet 50 weight is changing , not keeping imagenet weight

do you know how to test two images to get similiar score

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.