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

I will be grateful if model visualization script is collected in a test file, I tried to reproduce the test results after training model but failed. #50

Closed
ahmedshingaly opened this issue Sep 18, 2020 · 7 comments

Comments

@ahmedshingaly
Copy link

ahmedshingaly commented Sep 18, 2020

how to reproduce results. how can we create a demo file to test trained models and visualize results. I tried to reproduce the test results from trained weights but failed.
@hzxie @kondela @aashishbohra10

encoder = Encoder(cfg)
decoder = Decoder(cfg)
refiner = Refiner(cfg)
merger = Merger(cfg)

cfg.CONST.WEIGHTS = pretrained/Pix2Vox-A-ShapeNet.pth
chechpoint = torch.load(cfg.CONST.WEIGHTS, map_location=torch.device('cpu'))

fix_checkpoint = {}
fix_checkpoint['encoder_state_dict'] = orderedDict((k.split('module.')[1:][0], v) for k, v in checkpoint['encoder_state_dict'].items())
fix_checkpoint['decoder_state_dict'] = orderedDict((k.split('module.')[1:][0], v) for k, v in checkpoint['decoder_state_dict'].items())

epoch_idx = checkpoint['epoch_idx']
encoder.load_state_dict(fix_checkpoint['encoder_state_dict'])
decoder.load_state_dict(fix_checkpoint['decoder_state_dict'])

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

img1_path = '/datasets/ShapeNetRendering/02691156/1a04e3eab45ca15dd86060f189eb133/rendering/00.png'
img1_np = np.asarray(Image.open(img1_path))

sample = np.array([img1_np])

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(),
])

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_volum = decoder(image_features)

    if cfg.NETWORK.USE_MERFER and epoch_idx >= cfg.TRAIN.EPOCH_START_USE_REFINER:
        generated_volume = refiner(generated_volume)


generated_volume = generated_volume.squeeze(0)

img_dir= '/output/myresults'
gv = generated_volume.cpu().numpy()
rendering_views = utils.binvox_visualizatino.get_volume_views(gv, os.path.join(img_dir), epoch_idx)

Thank you in advance.

Originally posted by @ahmedshingaly in #28 (comment)

@ahmedshingaly ahmedshingaly changed the title I will be grateful if the above-mentioned script is collected in a test file, I tried to reproduce the test results but failed. I will be grateful if model visualization script is collected in a test file, I tried to reproduce the test results after training model but failed. Sep 18, 2020
@saisai1002
Copy link

saisai1002 commented Sep 21, 2020

What's the error message?

@hzxie
Copy link
Owner

hzxie commented Sep 21, 2020

rendering_views = utils.binvox_visualizatino.get_volume_views(gv, os.path.join(img_dir), epoch_idx)

should be changed to

rendering_views = utils.binvox_visualization.get_volume_views(gv, os.path.join(img_dir), epoch_idx)

@hzxie hzxie closed this as completed Sep 21, 2020
@hzxie
Copy link
Owner

hzxie commented Sep 21, 2020

Moreover,

cfg.CONST.WEIGHTS = pretrained/Pix2Vox-A-ShapeNet.pth

should be changed to

cfg.CONST.WEIGHTS = 'pretrained/Pix2Vox-A-ShapeNet.pth'

@hzxie
Copy link
Owner

hzxie commented Sep 21, 2020

Try to use OpenCV instead of Pillow.

Change

img1_np = np.asarray(Image.open(img1_path))

to

img1_np = cv2.imread(img1_path)

I'm not sure whether it will help. Maybe the orders of RGB won't affect the final reconstruction result.

@hzxie
Copy link
Owner

hzxie commented Sep 21, 2020

There're TOO MANY TYPOS in your code. Please check it carefully before asking questions.

Try to change

raw_features, generated_volum = decoder(image_features)

to

raw_features, generated_volume = decoder(image_features)

@saisai1002
Copy link

So,Can you provide the complete code for the single view test ?thx

@LiyingCV
Copy link

Greetings,
Do you resolve this issue? I also meet this issue and I still can not resolve it.

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

4 participants