Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__pycache__
checkpoint
data/*
!data/index_list/*
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
2 changes: 1 addition & 1 deletion dataloader/cifar100/autoaugment.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def __init__(self, p1, operation1, magnitude_idx1, p2, operation2, magnitude_idx
"translateY": np.linspace(0, 150 / 331, 10),
"rotate": np.linspace(0, 30, 10),
"color": np.linspace(0.0, 0.9, 10),
"posterize": np.round(np.linspace(8, 4, 10), 0).astype(np.int),
"posterize": np.round(np.linspace(8, 4, 10), 0).astype(np.int16),
"solarize": np.linspace(256, 0, 10),
"contrast": np.linspace(0.0, 0.9, 10),
"sharpness": np.linspace(0.0, 0.9, 10),
Expand Down
4 changes: 2 additions & 2 deletions dataloader/cifar100/cifar.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def SelectfromDefault(self, data, targets, index):
targets_tmp = []
for i in index:
ind_cl = np.where(i == targets)[0]
if data_tmp == []:
if len(data_tmp) == 0:
data_tmp = data[ind_cl]
targets_tmp = targets[ind_cl]
else:
Expand All @@ -155,7 +155,7 @@ def NewClassSelector(self, data, targets, index):
index = ind_np.reshape((5,5))
for i in index:
ind_cl = i
if data_tmp == []:
if len(data_tmp) == 0:
data_tmp = data[ind_cl]
targets_tmp = targets[ind_cl]
else:
Expand Down
2 changes: 1 addition & 1 deletion dataloader/cub200/autoaugment.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __init__(self, p1, operation1, magnitude_idx1, p2, operation2, magnitude_idx
"translateY": np.linspace(0, 150 / 331, 10),
"rotate": np.linspace(0, 30, 10),
"color": np.linspace(0.0, 0.9, 10),
"posterize": np.round(np.linspace(8, 4, 10), 0).astype(np.int),
"posterize": np.round(np.linspace(8, 4, 10), 0).astype(np.int16),
"solarize": np.linspace(256, 0, 10),
"contrast": np.linspace(0.0, 0.9, 10),
"sharpness": np.linspace(0.0, 0.9, 10),
Expand Down
2 changes: 1 addition & 1 deletion dataloader/imagenet100/autoaugment.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __init__(self, p1, operation1, magnitude_idx1, p2, operation2, magnitude_idx
"translateY": np.linspace(0, 150 / 331, 10),
"rotate": np.linspace(0, 30, 10),
"color": np.linspace(0.0, 0.9, 10),
"posterize": np.round(np.linspace(8, 4, 10), 0).astype(np.int),
"posterize": np.round(np.linspace(8, 4, 10), 0).astype(np.int16),
"solarize": np.linspace(256, 0, 10),
"contrast": np.linspace(0.0, 0.9, 10),
"sharpness": np.linspace(0.0, 0.9, 10),
Expand Down
2 changes: 1 addition & 1 deletion dataloader/imagenet1000/autoaugment.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __init__(self, p1, operation1, magnitude_idx1, p2, operation2, magnitude_idx
"translateY": np.linspace(0, 150 / 331, 10),
"rotate": np.linspace(0, 30, 10),
"color": np.linspace(0.0, 0.9, 10),
"posterize": np.round(np.linspace(8, 4, 10), 0).astype(np.int),
"posterize": np.round(np.linspace(8, 4, 10), 0).astype(np.int16),
"solarize": np.linspace(256, 0, 10),
"contrast": np.linspace(0.0, 0.9, 10),
"sharpness": np.linspace(0.0, 0.9, 10),
Expand Down
2 changes: 1 addition & 1 deletion dataloader/miniimagenet/autoaugment.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __init__(self, p1, operation1, magnitude_idx1, p2, operation2, magnitude_idx
"translateY": np.linspace(0, 150 / 331, 10),
"rotate": np.linspace(0, 30, 10),
"color": np.linspace(0.0, 0.9, 10),
"posterize": np.round(np.linspace(8, 4, 10), 0).astype(np.int),
"posterize": np.round(np.linspace(8, 4, 10), 0).astype(np.int16),
"solarize": np.linspace(256, 0, 10),
"contrast": np.linspace(0.0, 0.9, 10),
"sharpness": np.linspace(0.0, 0.9, 10),
Expand Down
2 changes: 1 addition & 1 deletion models/base/fscil_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, args):

if self.args.model_dir is not None:
print('Loading init parameters from: %s' % self.args.model_dir)
self.best_model_dict = torch.load(self.args.model_dir)['params']
self.best_model_dict = torch.load(self.args.model_dir, weights_only=False)['params']
#self.best_model_dict = torch.load(self.args.model_dir)['state_dict']
else:
print('random init params')
Expand Down
2 changes: 1 addition & 1 deletion models/fact/fscil_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, args):

if self.args.model_dir is not None:
print('Loading init parameters from: %s' % self.args.model_dir)
self.best_model_dict = torch.load(self.args.model_dir)['params']
self.best_model_dict = torch.load(self.args.model_dir, weights_only=False)['params']

else:
print('random init params')
Expand Down
2 changes: 1 addition & 1 deletion models/resnet18_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def load_state_dict_from_url(url, model_dir=None, map_location=None, progress=Tr
sys.stderr.write('Downloading: "{}" to {}\n'.format(url, cached_file))
hash_prefix = HASH_REGEX.search(filename).group(1)
_download_url_to_file(url, cached_file, hash_prefix, progress=progress)
return torch.load(cached_file, map_location=map_location)
return torch.load(cached_file, map_location=map_location, weights_only=False)


def _download_url_to_file(url, dst, hash_prefix, progress):
Expand Down
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "cvpr22-fact"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"matplotlib>=3.10.7",
"numpy>=2.3.4",
"scikit-learn>=1.7.2",
"torch>=2.9.0",
"torchvision>=0.24.0",
"tqdm>=4.67.1",
]
20 changes: 10 additions & 10 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@

MODEL_DIR=None
DATA_DIR = 'data/'
PROJECT='base'
PROJECT='fact' # base, fact

def get_command_line_parser():
parser = argparse.ArgumentParser()

# about dataset and network
parser.add_argument('-project', type=str, default=PROJECT)
parser.add_argument('-dataset', type=str, default='cub200',
parser.add_argument('-dataset', type=str, default='cifar100',
choices=['mini_imagenet', 'cub200', 'cifar100'])
parser.add_argument('-dataroot', type=str, default=DATA_DIR)

# about pre-training
parser.add_argument('-epochs_base', type=int, default=100)
parser.add_argument('-epochs_base', type=int, default=400)
parser.add_argument('-epochs_new', type=int, default=100)
parser.add_argument('-lr_base', type=float, default=0.1)
parser.add_argument('-lr_base', type=float, default=0.005)
parser.add_argument('-lr_new', type=float, default=0.1)
parser.add_argument('-schedule', type=str, default='Step',
parser.add_argument('-schedule', type=str, default='Milestone',
choices=['Step', 'Milestone','Cosine'])
parser.add_argument('-milestones', nargs='+', type=int, default=[60, 70])
parser.add_argument('-milestones', nargs='+', type=int, default=[50, 100, 150, 200, 250, 300])
parser.add_argument('-step', type=int, default=20)
parser.add_argument('-decay', type=float, default=0.0005)
parser.add_argument('-momentum', type=float, default=0.9)
parser.add_argument('-gamma', type=float, default=0.1)
parser.add_argument('-gamma', type=float, default=0.25)
parser.add_argument('-temperature', type=float, default=16)
parser.add_argument('-not_data_init', action='store_true', help='using average data embedding to init or not')
parser.add_argument('-batch_size_base', type=int, default=128)
parser.add_argument('-batch_size_base', type=int, default=256)
parser.add_argument('-batch_size_new', type=int, default=0, help='set 0 will use all the availiable training image for new')
parser.add_argument('-test_batch_size', type=int, default=100)
parser.add_argument('-base_mode', type=str, default='ft_cos',
Expand All @@ -38,8 +38,8 @@ def get_command_line_parser():
choices=['ft_dot', 'ft_cos', 'avg_cos']) # ft_dot means using linear classifier, ft_cos means using cosine classifier, avg_cos means using average data embedding and cosine classifier

#for fact
parser.add_argument('-balance', type=float, default=1.0)
parser.add_argument('-loss_iter', type=int, default=200)
parser.add_argument('-balance', type=float, default=0.01)
parser.add_argument('-loss_iter', type=int, default=0)
parser.add_argument('-alpha', type=float, default=2.0)
parser.add_argument('-eta', type=float, default=0.1)

Expand Down
6 changes: 3 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ def count_acc_taskIL(logits, label,args):

def confmatrix(logits,label,filename):

font={'family':'FreeSerif','size':18}
font={'family':'DejaVu Serif','size':18}
matplotlib.rc('font',**font)
matplotlib.rcParams.update({'font.family':'FreeSerif','font.size':18})
plt.rcParams["font.family"]="FreeSerif"
matplotlib.rcParams.update({'font.family':'DejaVu Serif','font.size':18})
plt.rcParams["font.family"]="DejaVu Serif"

pred = torch.argmax(logits, dim=1)
cm=confusion_matrix(label, pred,normalize='true')
Expand Down
Loading