Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some problems when test own multiple pictures #63

Closed
LiyingCV opened this issue Jan 19, 2021 · 4 comments
Closed

Some problems when test own multiple pictures #63

LiyingCV opened this issue Jan 19, 2021 · 4 comments

Comments

@LiyingCV
Copy link

LiyingCV commented Jan 19, 2021

Greetings,
I refered the #28 and #60 , when I input one picture or multiple pictures the output voxel is a low quality. I check my code for long time but I still cannot resolve it. Follow is the main multiple pictures test code.

    IMG_SIZE = cfg.CONST.IMG_H, cfg.CONST.IMG_W
    CROP_SIZE = cfg.CONST.CROP_IMG_H, cfg.CONST.CROP_IMG_W

    test_transforms = utils.data_transforms.Compose([
        utils.data_transforms.CenterCrop(IMG_SIZE, CROP_SIZE),
        utils.data_transforms.RandomBackground(cfg.TEST.RANDOM_BG_COLOR_RANGE),
        utils.data_transforms.Normalize(mean=cfg.DATASET.MEAN, std=cfg.DATASET.STD),
        utils.data_transforms.ToTensor(),
    ])
    encoder = Encoder(cfg)
    decoder = Decoder(cfg)
    refiner = Refiner(cfg)
    merger = Merger(cfg)

    if torch.cuda.is_available():
        encoder = torch.nn.DataParallel(encoder).cuda()
        decoder = torch.nn.DataParallel(decoder).cuda()
        refiner = torch.nn.DataParallel(refiner).cuda()
        merger = torch.nn.DataParallel(merger).cuda()

    print('Loading weights from %s ...' % (cfg.CONST.WEIGHTS))
    checkpoint = torch.load(cfg.CONST.WEIGHTS)
    encoder.load_state_dict(checkpoint['encoder_state_dict'])
    decoder.load_state_dict(checkpoint['decoder_state_dict'])

    if cfg.NETWORK.USE_REFINER:
        refiner.load_state_dict(checkpoint['refiner_state_dict'])
        print('load Refiner')
    if cfg.NETWORK.USE_MERGER:
        merger.load_state_dict(checkpoint['merger_state_dict'])
        print('load Merger')

    encoder.eval()
    decoder.eval()
    refiner.eval()
    merger.eval()

    img1_path = './imgs/'
    for i in range(3):
        img1_np = []
        img1_np = cv2.imread(img1_path + '%d.png' % i)

    sample = np.array([img1_np])

    rendering_images = test_transforms(rendering_images=sample)

    rendering_images = rendering_images.unsqueeze(0)

    with torch.no_grad():
        image_features = encoder(rendering_images)
        raw_features, generated_volume = decoder(image_features)
        if cfg.NETWORK.USE_MERGER:
            generated_volume = merger(raw_features, generated_volume)
        else:
            generated_volume = torch.mean(generated_volume, dim=1)

        if cfg.NETWORK.USE_REFINER:
            generated_volume = refiner(generated_volume)

    generated_volume = generated_volume.squeeze(0)

    img_dir = './imgs/result'
    gv = generated_volume.data.cpu().numpy()
    rendering_views = utils.binvox_visualization.get_volume_views(gv, os.path.join(img_dir),1)
    voxel2obj('prediction.obj', gv > 0.4)

voxels-000001
The input set:
inputs

Thank you in advance.

@hzxie
Copy link
Owner

hzxie commented Jan 19, 2021

Could you provide the results if you inference with each one of them?

@LiyingCV
Copy link
Author

Could you provide the results if you inference with each one of them?

If I used one picture:
1
The result is:
5
Acturally, the result is stranges. I also save the .obj file, it result stranges too:
6
I try to do swap axes np.swapaxes(voxels, 2, 1) but it seems not work.

@hzxie
Copy link
Owner

hzxie commented Jan 20, 2021

It seems that there is something wrong with the single-view reconstruction result.
Please refer to issues #28 and #60 to solve it first.

@hzxie hzxie closed this as completed Jan 20, 2021
@sujuyu
Copy link

sujuyu commented Apr 1, 2021

Greetings,
I refered the #28 and #60 , when I input one picture or multiple pictures the output voxel is a low quality. I check my code for long time but I still cannot resolve it. Follow is the main multiple pictures test code.

    IMG_SIZE = cfg.CONST.IMG_H, cfg.CONST.IMG_W
    CROP_SIZE = cfg.CONST.CROP_IMG_H, cfg.CONST.CROP_IMG_W

    test_transforms = utils.data_transforms.Compose([
        utils.data_transforms.CenterCrop(IMG_SIZE, CROP_SIZE),
        utils.data_transforms.RandomBackground(cfg.TEST.RANDOM_BG_COLOR_RANGE),
        utils.data_transforms.Normalize(mean=cfg.DATASET.MEAN, std=cfg.DATASET.STD),
        utils.data_transforms.ToTensor(),
    ])
    encoder = Encoder(cfg)
    decoder = Decoder(cfg)
    refiner = Refiner(cfg)
    merger = Merger(cfg)

    if torch.cuda.is_available():
        encoder = torch.nn.DataParallel(encoder).cuda()
        decoder = torch.nn.DataParallel(decoder).cuda()
        refiner = torch.nn.DataParallel(refiner).cuda()
        merger = torch.nn.DataParallel(merger).cuda()

    print('Loading weights from %s ...' % (cfg.CONST.WEIGHTS))
    checkpoint = torch.load(cfg.CONST.WEIGHTS)
    encoder.load_state_dict(checkpoint['encoder_state_dict'])
    decoder.load_state_dict(checkpoint['decoder_state_dict'])

    if cfg.NETWORK.USE_REFINER:
        refiner.load_state_dict(checkpoint['refiner_state_dict'])
        print('load Refiner')
    if cfg.NETWORK.USE_MERGER:
        merger.load_state_dict(checkpoint['merger_state_dict'])
        print('load Merger')

    encoder.eval()
    decoder.eval()
    refiner.eval()
    merger.eval()

    img1_path = './imgs/'
    for i in range(3):
        img1_np = []
        img1_np = cv2.imread(img1_path + '%d.png' % i)

    sample = np.array([img1_np])

    rendering_images = test_transforms(rendering_images=sample)

    rendering_images = rendering_images.unsqueeze(0)

    with torch.no_grad():
        image_features = encoder(rendering_images)
        raw_features, generated_volume = decoder(image_features)
        if cfg.NETWORK.USE_MERGER:
            generated_volume = merger(raw_features, generated_volume)
        else:
            generated_volume = torch.mean(generated_volume, dim=1)

        if cfg.NETWORK.USE_REFINER:
            generated_volume = refiner(generated_volume)

    generated_volume = generated_volume.squeeze(0)

    img_dir = './imgs/result'
    gv = generated_volume.data.cpu().numpy()
    rendering_views = utils.binvox_visualization.get_volume_views(gv, os.path.join(img_dir),1)
    voxel2obj('prediction.obj', gv > 0.4)

voxels-000001
The input set:
inputs

Thank you in advance.

Have you solved the problem?If so, can I refer to your solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants