SPICE icon indicating copy to clipboard operation
SPICE copied to clipboard

Have a similar problem to #29, but on CIFAR10

Open baofff opened this issue 2 years ago • 3 comments

Thanks for sharing the code.

I change the cluster number from 10 to 20, and I also stuck on the running local_consistency.py step.

This line of code idx_select, labels_select = model(feas_sim=feas_sim, scores=scores, forward_type="local_consistency") also outputs to empty tensor tensor([], dtype=torch.int64) tensor([], dtype=torch.int64).

How to address it on CIFAR10?

baofff avatar Aug 12 '22 04:08 baofff

Here is the reference to issue #29

baofff avatar Aug 12 '22 04:08 baofff

Thanks for your question. We didn't do overclustering in this study. Have you retrained the clustering head with 20 classes on CIFAR10? If you provide more details on your experiments, I could provide some specific suggestions.

niuchuangnn avatar Aug 12 '22 13:08 niuchuangnn

Thanks for the reply. My running command on training cluster head is python tools/train_self_v2.py --config-file ./configs/cifar10/spice_self.py --all 0. The config file is

num_cluster = 20
model_name = "spice_self_{}".format(num_cluster)
# pre_model = "./results/cifar10/moco/checkpoint_0999.pth.tar"
pre_model = "./results/cifar10/moco_res18_cls/checkpoint_0999.pth.tar"
embedding = "./results/cifar10/embedding/feas_moco_512_l2.npy"
resume = "./results/cifar10/{}/checkpoint_last.pth.tar".format(model_name)
# model_type = "clusterresnet"
# pre_model = "./results/cifar10/moco_res18/checkpoint_0999.pth.tar"
# embedding = "./results/cifar10/embedding_res18/feas_moco_512_l2.npy"
# resume = "./results/cifar10/{}/checkpoint_last.pth.tar".format(model_name)
model_type = "resnet18_cifar"
num_head = 10
num_workers = 4
device_id = 0
num_train = 5
batch_size = 5000
target_sub_batch_size = 100
train_sub_batch_size = 128
batch_size_test = 100
num_trans_aug = 1
num_repeat = 8
fea_dim = 512
att_conv_dim = num_cluster
att_size = 7
center_ratio = 0.5
sim_center_ratio = 0.9
epochs = 30
world_size = 1
workers = 4
rank = 0
dist_url = 'tcp://localhost:10001'
dist_backend = "nccl"
seed = None
gpu = None
multiprocessing_distributed = True

start_epoch = 0
print_freq = 1
test_freq = 1
eval_ent = False
eval_ent_weight = 0

data_train = dict(
    type="cifar10",
    root_folder="assets/datasets/cifar10",
    embedding=embedding,
    train=True,
    all=True,
    ims_per_batch=batch_size,
    shuffle=True,
    aspect_ratio_grouping=False,
    show=False,
    trans1=dict(
        aug_type="weak",
        crop_size=32,
        normalize=dict(mean=[0.485, 0.456, 0.406],
                       std=[0.229, 0.224, 0.225]),
    ),

    trans2=dict(
        aug_type="scan",
        crop_size=32,
        normalize=dict(mean=[0.485, 0.456, 0.406],
                       std=[0.229, 0.224, 0.225]),
        num_strong_augs=4,
        cutout_kwargs=dict(n_holes=1,
                           length=16,
                           random=True)
    ),
)

data_test = dict(
    type="cifar10",
    root_folder="assets/datasets/cifar10",
    embedding=embedding,
    train=True,
    all=True,
    shuffle=False,
    ims_per_batch=50,
    aspect_ratio_grouping=False,
    show=False,
    trans1=dict(
        aug_type="test",
        normalize=dict(mean=[0.485, 0.456, 0.406],
                       std=[0.229, 0.224, 0.225]),
    ),
    trans2=dict(
        aug_type="test",
        normalize=dict(mean=[0.485, 0.456, 0.406],
                       std=[0.229, 0.224, 0.225]),
    ),

)

model = dict(
    feature=dict(
        type=model_type,
        num_classes=num_cluster,
        in_channels=3,
        in_size=32,
        batchnorm_track=True,
        test=False,
        feature_only=True
    ),

    head=dict(type="sem_multi",
              multi_heads=[dict(classifier=dict(type="mlp", num_neurons=[fea_dim, fea_dim, num_cluster], last_activation="softmax"),
                                feature_conv=None,
                                num_cluster=num_cluster,
                                loss_weight=dict(loss_cls=1),
                                iter_start=epochs,
                                iter_up=epochs,
                                iter_down=epochs,
                                iter_end=epochs,
                                ratio_start=1.0,
                                ratio_end=1.0,
                                center_ratio=center_ratio,
                                )]*num_head,
              ),
    model_type="moco",
    pretrained=pre_model,
    freeze_conv=True,
)


solver = dict(
    type="adam",
    base_lr=0.005,
    bias_lr_factor=1,
    weight_decay=0,
    weight_decay_bias=0,
    target_sub_batch_size=target_sub_batch_size,
    batch_size=batch_size,
    train_sub_batch_size=train_sub_batch_size,
    num_repeat=num_repeat,
)

results = dict(
    output_dir="./results/cifar10/{}".format(model_name),
)

baofff avatar Aug 12 '22 13:08 baofff