Giter Club home page Giter Club logo

strhce's Introduction

Siamese Transformer with Hierarchical Concept Embedding for Fine-Grained Image Recognition

This is the official implementation of Siamese Transformer with Hierarchical Concept Embedding (STrHCE).

It is a challenging task to distinguish the subtle differences among fine-grained images from subordinate concepts, where the subconcepts are usually from a concept hierarchy. In this paper, we propose a Siamese Transformer with Hierarchical Concept Embedding (STrHCE), which contains two transformer subnetworks sharing all configurations and each is equipped with encoding the hierarchical semantic information at different concept levels into fine-grained image embeddings. Concretely, one subnetwork is for coarse-scale patches to learn the discriminative regions with the aid of the innate multi-head self-attention mechanism of transformer. The other is for finer-scale patches (which are adaptively sampled from the discriminative regions) to capture subtle yet discriminative visual cues and eliminate redundant information. STrHCE connects two subnetworks via a score margin adjustor to enforce the most discriminative regions generating more confident predictions. Extensive experiments have been conducted on four commonly-used benchmark datasets including CUB-200- 2011, FGVC-Aircraft, Stanford Dogs and NABirds, and empirically demonstrate the superiority of the proposed STrHCE by comparing with the state-of-the-art baselines.

arch

Requirement

The code is tested on:

  • pytorch==1.8.0
  • torchvision==0.7.0
  • timm==0.4.5

Use pip or conda to install all dependencies:

pip install -r requirements.txt

or

conda install --file requirements.txt

Usage

Run the following command to train the model used in the paper:

DATASET="cub2011"
python train.py cub2011hier2 \
  --datadir="dataset/$DATASET" \
  --logdir="results/$DATASET/strhce" \
  --arch=vit_deit_small_distilled_patch16_224 \
  --epoch=100 \
  --batch-size=8 \
  --lr=1e-3 \
  --lr-step=30 \
  --lr-policy=step \
  --wd=1e-4 \
  --print-freq=100 \
  --worker=4 \
  --pretrained \
  --seed=0 \
  --use-amp \
  --ngpus=2 \
  --dist-url="tcp://127.0.0.1:10001" \
  --multiprocessing-distributed \
  --world-size=1 \
  --rank=0 \
  --concept-level=3

The dataset will be automatically downloaded and prepared in ./datasets when first run. After preparing the dataset, please move the file in datasets/hierarchy/ to the corresponding dataset directory.

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.