Code Monkey home page Code Monkey logo

class-agnostic-few-shot-object-counting's Introduction

Class agnostic Few shot Object Counting

This repository is the non-official pytorch implementation of a WACV 2021 Paper "Class-agnostic Few-shot-Object-Counting". Link

In Proc. IEEE/CVF Winter Conference on Applications of Computer Vision (WACV), 2021 Shuo-Diao Yang, Hung-Ting Su, Winston H. Hsu, Wen-Chin Chen*

39_ref_good

2_ref_good

Installation

Our code has been implemented on Python 3.8 and PyTorch 1.8.1+cu101. Please follow the instructions to setup your environment. See other required packages in requirements.txt.

conda create --name CFOCNet python=3.8
conda activate CFOCNet
pip install -r requirements.txt
pip install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"

If you have problem about installing cocoapi, come here to find the official documentation.

Getting Started

  • CFOCNet_demo.ipynb This notebook tests the detail implementations of CFOCNet, giving insights such as how the size of each tensor changes across each stage.
  • model This directory contains all related modules of our CFOCNet implementation
  • Eval_Result This directory contains the ideal results during evaluation stage, where an example's predicted count and the density map aligns with the groundtruth.

Data Preparation

We train and evaluate our methods on COCO dataset 2017.
Please follow the instruction here to download the COCO dataset 2017
structure used in our code will be like :

$PATH_TO_DATASET/
├──── images
│    ├──── train2017
│             |──── 118287 images (.jpg)
│
│    ├──── test2017
│             |──── 40670 images (.jpg)
│
│    ├──── val2017
│             |──── 5000 images (.jpg)
│
├──── annotations
│    ├──── captions_train2017.json
│
│    ├──── captions_val2017.json
│
│    ├──── instances_train2017.json
|
│    ├──── instances_val2017.json
│
│    ├──── person_keypoints_train2017.json
│
│    ├──── person_keypoints_val2017.json

After downloading the data, please navigate to our repository.
Then, modify the variable "coco_path" in line 8 in crop.py to your COCO dataset path.

cd CODE_DIRECTORY
python data/crop.py

After performing the above instructions, the structure of your coco dataset will be like :

$PATH_TO_DATASET/
├──── images
│    ├──── train2017
│             |──── 118287 images (.jpg)
│
│    ├──── test2017
│             |──── 40670 images (.jpg)
│
│    ├──── val2017
│             |──── 5000 images (.jpg)
│
│    ├──── crop
│             |──── 80 directories which store all categories 500 images in coco dataset 2017 (for references images)
│
├──── annotations
│    ├──── captions_train2017.json
│
│    ├──── captions_val2017.json
│
│    ├──── crop.json
│
│    ├──── instances_train2017.json
|
│    ├──── instances_val2017.json
│
│    ├──── person_keypoints_train2017.json
│
│    ├──── person_keypoints_val2017.json

Training

  • Please go to config.yaml to change the configs under "train".
  • To setup the training process, model configurations such as epochs, batch_size, and result_path can be tuned, all of which are stored in config.yaml
  • Modify run.sh to setup the training process python main.py --config=config.yaml --doc=doc_name --train.
  • doc_name can be any string you want.
  • Execute the bash script through the below command:
cd CODE_DIRECTORY
bash run.sh
  • After running the code, you will find your training logs under CODE_DIRECTORY/exp/logs/doc_name

Testing

  • Please go to config.yaml to change the configs under "eval".
  • To setup the testing process, the configurations such as checkpoint, sample, and image_folder can be tuned, all of which are stored in config.yaml.
  • Modify run.sh to setup the testing process python main.py --config=config.yaml --doc=doc_name --test
  • doc_name can be any string you want.
  • Execute the bash script through the below command
cd CODE_DIRECTORY
bash run.sh
  • After running the code, you will find your testing logs under "CODE_DIRECTORY/exp/logs/doc_name".

Implementation Details

  • The runner architecture is from NCSNv2.
  • We crop 500 reference images for each categories.
  • For query image, instead of random crop, we resize it with aspect ratio and padding to 256 x 256.
  • The default setting in our code is 5-shot learning, where each query image has 5 reference images to learn.

Acknowledgement

class-agnostic-few-shot-object-counting's People

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.