def main():
    root = r"/media/root/文档/wqr/my_spixel_fcn/data_preprocessing/up_facet"
    dataset = Data_api_rec(root=root)
    from data_api.get_dataset_mean_std import get_mean_std
    a, b, _ = dataset[0]
    mean, std = get_mean_std(dataset, ratio=0.1)
    # print(mean)
    # print(std)
    # exit()
    # print(a.shape)
    # print(b.shape)
    from torchvision import transforms
    tran = transforms.ToPILImage()
    imga = tran(a)
    imgb = tran(b)
    imgaa = cv2.cvtColor(np.array(imga), cv2.COLOR_RGB2BGR)

    cv2.imshow("a", np.uint8(imgaa))
    cv2.imshow("b", np.uint8(imgb))
    cv2.waitKey()
test_parser.add_argument("--continue_train",
                         "-ct",
                         default=False,
                         type=bool,
                         help="continue train using trained model")
test_parser.add_argument(
    "--state_path",
    "-sp",
    default="checkpoints/network_state/acc94.74_model.pth",
    help="the p500ath of trained model")

opt = test_parser.parse_args()
print(opt.device)
# 获取数据集的均值、方差
Norm, [mean,
       std] = get_mean_std(mean_std_path=os.path.join(base_path, "data_api"))
test_data = Data_image_label(root=opt.data_root,
                             updata_txt=True,
                             train_test_ratio=0.0,
                             phase="test",
                             Norm=Norm)
test_loader = DataLoader(test_data, batch_size=opt.batch_size, shuffle=False)

# model
model = Res18_UNet(n_classes=2, layer=4).to(opt.device)

# device_ids = [0]
# model = torch.nn.DataParallel(model, device_ids=device_ids)
# model = model.cuda(device=device_ids[0])

model.eval()
Esempio n. 3
0
train_parser.add_argument("--state_path",
                          "-sp",
                          default="checkpoints/network_state/network_epo1.pth",
                          help="the path of trained model")

opt = train_parser.parse_args()
print(opt.device)
train_data = Data_api_rec(root=opt.data_root,
                          gen_label=False,
                          updata_txt=False,
                          train_test_ratio=0.8,
                          phase="train",
                          use_relative_path=False)

Norm, [mean,
       std] = get_mean_std(mean_std_path=os.path.join(base_path, "data_api"),
                           dataset=train_data)

train_data = Data_api_rec(root=opt.data_root,
                          gen_label=False,
                          updata_txt=False,
                          train_test_ratio=0.8,
                          phase="train",
                          use_relative_path=False,
                          Norm=Norm)
val_data = Data_api_rec(root=opt.data_root,
                        gen_label=False,
                        updata_txt=False,
                        train_test_ratio=0.8,
                        phase="val",
                        Norm=Norm)