Esempio n. 1
0
def main():
    global args, num_batches, use_gpu
    if not args.zeroTrain:
        model = models.sigmoid_ResnetModel(args.arch, 224, args.num_classs,
                                           args.Conv_Type, args.Branch,
                                           args.Conv_Num)
        if args.resume:
            checkpoint = torch.load(args.resume)
            model.load_state_dict(checkpoint, strict=True)

        if use_gpu:
            model = model.cuda()
            print("Use GPU!")
        else:
            print("Use CPU!")

        train_loader = dataset.train_loader(args.train_path,
                                            args.relative_path,
                                            batch_size=args.batch_size,
                                            num_workers=10,
                                            pin_memory=True)
        #test_train_loader = dataset.test_loader(args.test_path, args.relative_path, batch_size=1, num_workers=5, pin_memory=True)
        #val_loader = dataset.test_loader(args.val_path, args.relative_path, batch_size=1, num_workers=5, pin_memory=True)
        # test_loader = dataset.test_loader(rgs.test_path, args.relative_path, batch_size=1, num_workers=5, pin_memory=True)

    train_val(model,
              train_loader,
              test_train_loader=None,
              val_loader=None,
              print_freq=args.print_freq,
              optimizer=None,
              epoches=args.epochs,
              Branch=args.Branch)
Esempio n. 2
0
def main():
    global args, num_batches, use_gpu
    model = models.sigmoid_ResnetModel('Resnet152', 224, args.num_classs, 2,
                                       17, 5)
    if args.resume:
        checkpoint = torch.load(args.resume)
        model.load_state_dict(checkpoint, strict=True)

    if use_gpu:
        model = model.cuda()
        print("Use GPU!")
    else:
        print("Use CPU!")

    csvfile = open('./Consumer_loss.csv', 'wb')
    fieldnames = ['img path', 'total loss']
    writer = csv.DictWriter(csvfile, delimiter=',', fieldnames=fieldnames)  #
    writer.writeheader()
    data_loader = dataset.train_loader(args.data_path,
                                       args.relative_path,
                                       batch_size=16,
                                       num_workers=10,
                                       pin_memory=True)

    get_data_loss(csvfile, writer, model, data_loader)
Esempio n. 3
0
def main():
    time1 = time()
    global args, use_gpu
    input_size = args.input_size

    resume1 = './checkpoint/BBX/NewAnnoCleaned/Resnet152_64_{}_Epoch.pth'
    # resume2 = './checkpoint/BBX/sigmoid_model/Lr_0_001/Five_Branch/Bottleneck/Five_Depth/Resnet152_64_{}_Epoch.pth'
    test_loader = dataset.test_loader(args.test_path,
                                      args.relative_path,
                                      batch_size=args.batch_size,
                                      num_workers=10,
                                      pin_memory=True)

    model = models.sigmoid_ResnetModel(args.arch, 224, args.num_classs, 2, 17,
                                       5)
    for i in range(49, 48, -1):
        f = open(
            './result/NewAnnoCleaned/LR_0_001_FiveDepth_epoch_{}_top3_top5.txt'
            .format(str(i)), 'w')
        print("{}  epoch".format(str(i)))
        checkpoint = torch.load(resume1.format(str(i)))
        model.load_state_dict(checkpoint, strict=True)
        f.write("{} epoch\n".format(str(i)))
        if use_gpu:
            model = model.cuda()
        else:
            pass
        if args.Branch == 1:
            # _, _, overall_top3_recall, overall_top5_recall = top3_5_recall(model, test_loader, topk=(3,5), epoch=i)
            pass
        elif args.Branch == 17:
            _, _, overall_top3_recall, overall_top5_recall = recall_precision(
                model, test_loader, topk=(3, 5), epoch=i)
        f.write("top-3  ")
        for key in overall_top3_recall.keys():
            f.write("{}  ".format(key))
        f.write("\n")
        for _, value in overall_top3_recall.items():
            f.write("{}  ".format(str(round(value * 100, 3))))
        f.write("\n")

        f.write("top-5  ")
        for key in overall_top5_recall.keys():
            f.write("{}  ".format(key))
        f.write("\n")
        for _, value in overall_top5_recall.items():
            f.write("{}  ".format(str(round(value * 100, 3))))
        f.write("\n")
        f.close()

    print("total time is: {} seconds".format(round(time() - time1, 2)))
Esempio n. 4
0
 def __init__(self, modelPath=attrModelPath,\
                 namePath=attrNamePath, savePath=attrSavePath, inputSize=224):
     super(attributesForward, self).__init__()
     self.modelPath = modelPath
     self.namePath  = namePath
     self.numClasses, self.idx2class = attributesNameParser(self.namePath)
     self.savePath  = savePath
     self.inputSize = inputSize
     self.model = models.sigmoid_ResnetModel('Resnet152', self.inputSize, \
                 self.numClasses, 2, 17, 5)
     self.model.load_state_dict(torch.load(modelPath), strict=True)
     if useGpu:
         self.model = self.model.cuda()
         self.model.eval()
     else:
         self.model.eval()