colab运行fvr模型注意点

登陆googledrive-挂载数据集-建立snapshots文件夹
然后开始运行
**本次fvr模型设置:**数据集是SDMULA,损失函数是softmax,使用的网络是lenet,最多训练60个epoch

batch_size=4, dataset='SDMULA', feature_dim=128, gamma_cos=1.0, gamma_tri=1.0, hard_margin=0.2, k=4, log_interval=10, loss='softmax', lr=0.01, lr_decay=0.1, lr_fc=0.1, m=0.2, max_epoch=60, momentum=0.9, network='lenet++', openset=False, p=8, plot=False, pretrained=False, s=15.0, seed=1, wd=0.0005

训练结果:
准确率最高的是在第43轮:seed=1_dataset=SDMULA_network=lenet++_loss=softmax_BestCMC=98.93_Epoch=43
但是一共训练了60轮:
snapshots输出为:seed=1_dataset=SDMULA_network=lenet++_loss=softmax_FinalCMC=98.84_Epoch=59

遇到的bug及解决方法:

  1. 需要注意的是在datasets.py和train.py文件里得把文件路径都改成挂载在colab上的数据集的路径,否则cv2.imread会找不到路径,从而image为空值,就会报出“NoneType” object has no attribute ‘array_interface’。
  2. RuntimeError: Given groups=1, weight of size 32 1 5 5, expected input[4, 3, 64, 144] to have 1 channels, but got 3 channels instead
    这里要注意怎么改下datasets.py,这里用的是lenet所以应该这样:
class FingerVeinDataset(Dataset):
    def __init__(self, filelist_path, dataset_path, class_num, transform=None):
        filelist = open(filelist_path).readlines()
        self.img_paths = [line.split()[0] for line in filelist]
        self.labels = [int(line.split()[1]) for line in filelist]
        self.dataset_path = dataset_path
        self.transform = transform
        self.class_num = class_num

    def __getitem__(self, item):
        image = Image.open(os.path.join(self.dataset_path, self.img_paths[item]))
        #image = cv2.imread(os.path.join(self.dataset_path, self.img_paths[item]))
        #image = Image.fromarray(image)
        target = self.labels[item]
        if self.transform is not None:
            image = self.transform(image)
        return image, target

lenet的话要用open读入,resnet18的话要用imread和fromarray读入。
如果用的网络是lenet但是却用imread和fromarray读入,就会报出以上错误。
如果用的网络是lenet,在open保留,imread没有,fromarray有的情况下就会报错epected string or buffer,因为open读到的内容已经是PIL格式了,不用再转换了。
3.报错如图,找不到snapshots文件夹及路径
报错如图,找不到snapshots文件夹及路径。这个时候应该把.改为/content,然后在colab的文件目录里建立一个snapshots文件夹即可。

到此数据集就在模型上就跑起来了!!
下一步是改用resnet18网络去训练,关注openset场景(测试集类别和训练集类别不重合),注意打开openset的话run的时候加一个-openset参数。
跑一些实验结果 理解代码 修改代码
理解如何做性能评价 比如怎么做verification的?什么是roc,eer?
加油冲冲冲!!!

你可能感兴趣的:(colab运行fvr模型注意点)