import matplotlib.pyplot as plt
    plt.figure(figsize=figsize)
    plt.imshow(x, interpolation='nearest', cmap='jet')
    if title:
        plt.title(title)
    if cbar:
        plt.colorbar()
    plt.show()


if __name__ == '__main__':

    args = parse_args()

    model1 = DnCNN()
    model2 = DecomposeNet(image_channels=5, n_block=32)
    model3

    # model = torch.load(os.path.join(args.model_dir, args.model_name))
    model.load_state_dict(
        torch.load(os.path.join(args.model_dir, args.model_name)))
    decompose_model.load_state_dict(
        torch.load(os.path.join(args.decom_model_dir, args.decom_model_name)))
    # model = torch.load(os.path.join(args.model_dir, args.model_name))
    log('load trained model')

    #    params = model.state_dict()
    #    print(params.values())
    #    print(params.keys())
    #
    #    for key, value in params.items():
    import matplotlib.pyplot as plt
    plt.figure(figsize=figsize)
    plt.imshow(x, interpolation='nearest', cmap='jet')
    if title:
        plt.title(title)
    if cbar:
        plt.colorbar()
    plt.show()


if __name__ == '__main__':

    args = parse_args()

    model = DnCNN()
    decompose_model = DecomposeNet(image_channels=5, n_block=32)

    if not os.path.exists(
            os.path.join(args.decom_model_dir, args.decom_model_name)):
        decompose_model = torch.load(os.path.join(args.model_dir, 'model.pth'))
        # load weights into new model
        log('load trained model on Train400 dataset by kai')
    else:
        model = torch.load(os.path.join(args.model_dir, args.model_name))
        # model.load_state_dict(torch.load(os.path.join(args.model_dir, args.model_name)))
        decompose_model.load_state_dict(
            torch.load(
                os.path.join(args.decom_model_dir, args.decom_model_name)))
        # model = torch.load(os.path.join(args.model_dir, args.model_name))
        log('load trained model')
        dim=1)
    Low_output = torch.cat(
        (torch.tensor(np.real(np.fft.ifft2(Low_freq))).unsqueeze(1).float(),
         torch.tensor(np.imag(np.fft.ifft2(Low_freq))).unsqueeze(1).float()),
        dim=1)

    return High_output, Low_output


if not os.path.exists(save_dir):
    os.mkdir(save_dir)

if __name__ == '__main__':
    # model selection
    print('===> Building model')
    model_hf = DecomposeNet(image_channels=2, n_block=32)
    model_lf = DecomposeNet(image_channels=2, n_block=32)

    initial_epoch = findLastCheckpoint(
        save_dir=save_dir)  # load the last model in matconvnet style
    if initial_epoch > 0:
        print('resuming by loading epoch %03d' % initial_epoch)
        model_hf.load_state_dict(
            torch.load(
                os.path.join(save_dir, 'high_model_%03d.pth' % initial_epoch)))
        model_lf.load_state_dict(
            torch.load(
                os.path.join(save_dir, 'low_model_%03d.pth' % initial_epoch)))
        # model_hf = torch.load(os.path.join(save_dir, 'high_model_%03d.pth' % initial_epoch))
        # model_lf = torch.load(os.path.join(save_dir, 'low_model_%03d.pth' % initial_epoch))
    model_hf.train()
batch_size = args.batch_size
cuda = torch.cuda.is_available()
n_epoch = args.epoch
sigma = args.sigma
save_dir = args.save_dir

# save_dir = os.path.join('models', args.model+'_' + 'sigma' + str(sigma))

if not os.path.exists(save_dir):
    os.mkdir(save_dir)

if __name__ == '__main__':
    # model selection
    print('===> Building model')
    model = DecomposeNet()

    initial_epoch = findLastCheckpoint(save_dir=save_dir)  # load the last model in matconvnet style
    if initial_epoch > 0:
        print('resuming by loading epoch %03d' % initial_epoch)
        # model.load_state_dict(torch.load(os.path.join(save_dir, 'model_%03d.pth' % initial_epoch)))
        # model = torch.load(os.path.join(save_dir, 'model_%03d.pth' % initial_epoch))
    model.train()
    # criterion = nn.MSELoss(reduction = 'sum')  # PyTorch 0.4.1
    # criterion = sum_squared_error()
    criterion = nn.MSELoss()

    if cuda:
        model = model.cuda()
        # device_ids = [0]
        # model = nn.DataParallel(model, device_ids=device_ids).cuda()
        dim=1)
    Low_output = torch.cat(
        (torch.tensor(np.real(np.fft.ifft2(Low_freq))).unsqueeze(1).float(),
         torch.tensor(np.imag(np.fft.ifft2(Low_freq))).unsqueeze(1).float()),
        dim=1)

    return High_output, Low_output


if not os.path.exists(save_dir):
    os.mkdir(save_dir)

if __name__ == '__main__':
    # model selection
    print('===> Building model')
    model = DecomposeNet(image_channels=4, n_block=32)
    # model_lf = DecomposeNet(image_channels=2, n_block=32)

    initial_epoch = findLastCheckpoint(
        save_dir=save_dir)  # load the last model in matconvnet style

    if initial_epoch > 0:
        print('resuming by loading epoch %03d' % initial_epoch)
        model.load_state_dict(
            torch.load(os.path.join(save_dir,
                                    'model_%03d.pth' % initial_epoch)))

        # model_hf = torch.load(os.path.join(save_dir, 'high_model_%03d.pth' % initial_epoch))
        # model_lf = torch.load(os.path.join(save_dir, 'low_model_%03d.pth' % initial_epoch))
    model.train()
    # criterion = nn.MSELoss(reduction = 'sum')  # PyTorch 0.4.1
        dim=1)
    Low_output = torch.cat(
        (torch.tensor(np.real(np.fft.ifft2(Low_freq))).unsqueeze(1).float(),
         torch.tensor(np.imag(np.fft.ifft2(Low_freq))).unsqueeze(1).float()),
        dim=1)

    return High_output, Low_output


if not os.path.exists(save_dir):
    os.mkdir(save_dir)

if __name__ == '__main__':
    # model selection
    print('===> Building model')
    decompose_model = DecomposeNet(image_channels=5, n_block=32)
    compose_model = ComposeNet(n_block=32)

    initial_epoch = findLastCheckpoint(
        save_dir=save_dir)  # load the last model in matconvnet style
    # initial_epoch = 1
    if initial_epoch > 0:
        print('resuming by loading epoch %03d' % initial_epoch)
        decompose_model.load_state_dict(
            torch.load(
                os.path.join(save_dir,
                             'decom_model_%03d.pth' % initial_epoch)))
        # model = torch.load(os.path.join(save_dir, 'model_%03d.pth' % initial_epoch))

    # criterion = nn.MSELoss(reduction = 'sum')  # PyTorch 0.4.1
    # criterion = sum_squared_error()
Exemplo n.º 7
0
    import matplotlib.pyplot as plt
    plt.figure(figsize=figsize)
    plt.imshow(x, interpolation='nearest', cmap='jet')
    if title:
        plt.title(title)
    if cbar:
        plt.colorbar()
    plt.show()



if __name__ == '__main__':

    args = parse_args()

    model = DecomposeNet(image_channels=4, n_block=32)

    if not os.path.exists(os.path.join(args.model_dir, args.model_name)):
        model = torch.load(os.path.join(args.model_dir, 'model.pth'))
        # load weights into new model
        log('load trained model on Train400 dataset by kai')
    else:
        model.load_state_dict(torch.load(os.path.join(args.model_dir, args.model_name)))
        # model = torch.load(os.path.join(args.model_dir, args.model_name))
        log('load trained model')

#    params = model.state_dict()
#    print(params.values())
#    print(params.keys())
#
#    for key, value in params.items():
Exemplo n.º 8
0
    import matplotlib.pyplot as plt
    plt.figure(figsize=figsize)
    plt.imshow(x, interpolation='nearest', cmap='gray')
    if title:
        plt.title(title)
    if cbar:
        plt.colorbar()
    plt.show()



if __name__ == '__main__':

    args = parse_args()

    model = DecomposeNet()

    if not os.path.exists(os.path.join(args.model_dir, args.model_name)):
        model = torch.load(os.path.join(args.model_dir, 'model.pth'))
        # load weights into new model
        log('load trained model on Train400 dataset by kai')
    else:
        model.load_state_dict(torch.load(os.path.join(args.model_dir, args.model_name)))
        # model = torch.load(os.path.join(args.model_dir, args.model_name))
        log('load trained model')

#    params = model.state_dict()
#    print(params.values())
#    print(params.keys())
#
#    for key, value in params.items():