Giter Site home page Giter Site logo

iciclegcn's Introduction

Deep image clustering with contrastive learning and multi-scale graph convolutional networks (IcicleGCN)

This is the code for our Pattern Recognition'24 paper "Deep image clustering with contrastive learning and multi-scale graph convolutional networks"

Dependency

  • python>=3.7
  • pytorch>=1.6.0
  • torchvision>=0.8.1
  • munkres>=1.1.4
  • numpy>=1.19.2
  • opencv-python>=4.4.0.46
  • pyyaml>=5.3.1
  • scikit-learn>=0.23.2
  • cudatoolkit>=11.0

Usage

Configuration

There is a configuration file "config/config.yaml", where one can edit both the training and test options of the first stage.

In the file "icicleGCN.py", where one can edit training options of the second stage.

Training

Take dataset ImageNet-10 as an example:

First stage: After setting the configuration, to start first stage training, use the checkpoint_1000.tar to warm up the whole network, simply run

python train.py

Second stage: After setting the configuration, to start second stage training, use the checkpoint_1015.tar which was training in the first stage as the pretrain work for second stage train, simply run

python icicleGCN.py

Test

Once the first training is completed, there will be a saved model in the "model_path" specified in the configuration file "config.yaml". To test the trained model of first stage, run

python cluster.py

Once the second training is completed, there will be a saved model in the "test_path" specified in the file "icicleGCN.py". To test the trained model of second stage, run

python icicleGCN_test

and the final results will be save in file "icicleGCN_result" in TXT format

We uploaded the pretrained model which achieves the performance reported in the paper to the "save_IcicleGCN" folder for reference.

Dataset

CIFAR-10, CIFAR-100, STL-10 will be automatically downloaded by Pytorch. Tiny-ImageNet can be downloaded from http://cs231n.stanford.edu/tiny-imagenet-200.zip. For ImageNet-10 and ImageNet-dogs, we provided their description in the "dataset" folder.

Download

Anyone clicking on this link before December 09, 2023 will be taken directly to the final version of my article on ScienceDirect, which you are welcome to read or download.

https://authors.elsevier.com/c/1hyKE77nKkYIC

Citation

We are truly grateful for citing our paper! The BibTex entry of our paper is:

@article{xu2024deep, title={Deep image clustering with contrastive learning and multi-scale graph convolutional networks}, author={Xu, Yuankun and Huang, Dong and Wang, Chang-Dong and Lai, Jian-Huang}, journal={Pattern Recognition}, pages={110065}, year={2024}, publisher={Elsevier} }

iciclegcn's People

Contributors

xuyuankun631 avatar

Stargazers

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

Watchers

 avatar  avatar

iciclegcn's Issues

Training resnet34 (from scratch) on CIFAR-10 leads to nan loss

I am training the resnet34 from scratch on CIFAR-10 dataset, also changed some params in train.py as well.

# --config.yaml--

# general
seed: 42
workers: 4
dataset_dir: "./datasets"

# train options
batch_size: 100
image_size: 224
start_epoch: 0
epochs: 1015
dataset: "CIFAR-10" #  CIFAR-10 / CIFAR-100 / STL-10 / ImageNet-10 / ImageNet-dogs / tiny-ImageNet / Flowers17

# model options
resnet: "ResNet34" # ResNet18 / ResNet34 / ResNet50
feature_dim: 128
model_path: "./save/CIFAR-10"
reload: False

# loss options
learning_rate: 0.001 #
weight_decay: 0.0001
instance_temperature: 0.5
cluster_temperature: 1.0

Training the model from scratch lead to nan just in a single epoch -

# --terminal output--
Files already downloaded and verified
Files already downloaded and verified
Step [0/600]       loss_instance: 5.28515625      loss_cluster: 2.946188449859619        re_loss: 1.126003384590149      
Step [50/600]      loss_instance: 5.009121417999268       loss_cluster: 2.4746360778808594       re_loss: 0.034027669578790665   
Step [100/600]     loss_instance: 4.926772117614746       loss_cluster: 2.2181878089904785       re_loss: 0.024739207699894905   
Step [150/600]     loss_instance: 4.885540962219238       loss_cluster: 2.2527127265930176       re_loss: 0.04029698297381401    
Step [200/600]     loss_instance: 4.774231910705566       loss_cluster: 2.339139699935913        re_loss: 0.05486036837100983    
Step [250/600]     loss_instance: 4.869399547576904       loss_cluster: 2.6640102863311768       re_loss: 0.03202003985643387    
Step [300/600]     loss_instance: 5.103700160980225       loss_cluster: 2.4775240421295166       re_loss: 0.034477513283491135   
Step [350/600]     loss_instance: 4.827446937561035       loss_cluster: 2.7474653720855713       re_loss: 0.03616001829504967    
Step [400/600]     loss_instance: 4.9964423179626465      loss_cluster: 2.49931263923645         re_loss: 0.03911386430263519    
Step [450/600]     loss_instance: 5.18294620513916        loss_cluster: 2.3889520168304443       re_loss: 0.029943885281682014   
Step [500/600]     loss_instance: nan     loss_cluster: nan      re_loss: nan    
Step [550/600]     loss_instance: nan     loss_cluster: nan      re_loss: nan 

I tried default training params as well, but it also led to nan after around 60 epochs. Is there anything I am missing over here?

Q:class load_data(Dataset):

When I was running the icicleGCN.py at a new dataset, I want to know the type of __.txt and __label.txt. I can not find them at your files.
" def init(self, dataset):
self.x = np.loadtxt('data/{}.txt'.format(dataset), dtype=float)
# self.x = np.loadtxt('data/{}.txt'.format(dataset), dtype=str)
self.y = np.loadtxt('data/{}_label.txt'.format(dataset), dtype=int)"

Could you tell me the format of these two files?

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.