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 want to use only tex-pifu #150

Open
Yumekawa-chan opened this issue Apr 28, 2023 · 0 comments
Open

I want to use only tex-pifu #150

Yumekawa-chan opened this issue Apr 28, 2023 · 0 comments

Comments

@Yumekawa-chan
Copy link

Yumekawa-chan commented Apr 28, 2023

I made Avatar by ECON(https://github.com/YuliangXiu/ECON).
But this doesn't support predict back texture, so only front texture.
That's why I edited gen_mesh_color in PIFu's train_utils.py to add the code that gives the texture to the ECON avatar. Specifically, I assigned the vertex information of the avatar generated by ECON to the variable verts. As a result, the avatar and the texture are misaligned and a mysterious texture is applied.

Can someone please help me?

This code is gen_mesh_color function of train_urils.py.

`def gen_mesh_color(opt, netG, netC, cuda, data, save_path, use_octree=True):
image_tensor = data["img"].to(device=cuda)
calib_tensor = data["calib"].to(device=cuda)

netG.filter(image_tensor)
netC.filter(image_tensor)
netC.attach(netG.get_im_feat()) 
print("netC: ",type(netC))
print("netG: ",type(netG))
b_min = data["b_min"]
b_max = data["b_max"]
try:
    save_img_path = save_path[:-4] + ".png"
    save_img_list = []
    for v in range(image_tensor.shape[0]):
        save_img = (
            np.transpose(image_tensor[v].detach().cpu().numpy(), (1, 2, 0)) * 0.5
            + 0.5
        )[:, :, ::-1] * 255.0
        save_img_list.append(save_img)
    save_img = np.concatenate(save_img_list, axis=1)
    Image.fromarray(np.uint8(save_img[:, :, ::-1])).save(save_img_path)

    verts, faces, _, _ = reconstruction(
        netG,
        cuda,
        calib_tensor,
        opt.resolution,
        b_min,
        b_max,
        use_octree=use_octree,
    ) # pifuの点群の生成

    verts = np.load("/mnt/hdd1/mikihiro/work/tex-pifu/src/utils/01_Color.npy") # iconの点群の読み込み

    # verts = scaling(verts2, verts)


    # Now Getting colors
    verts_tensor = torch.from_numpy(verts.T).unsqueeze(0).to(device=cuda).float()
    verts_tensor = reshape_sample_tensor(verts_tensor, opt.num_views)
    color = np.zeros(verts.shape)
    interval = 10000
    for i in range(len(color) // interval):
        left = i * interval
        right = i * interval + interval
        if i == len(color) // interval - 1:
            right = -1
        netC.query(verts_tensor[:, :, left:right], calib_tensor)
        rgb = netC.get_preds()[0].detach().cpu().numpy() * 0.5 + 0.5
        color[left:right] = rgb.T

    np.save("01_Color_points.npy",verts)
    np.save("01_Color_colors.npy",color)

    save_obj_mesh_with_color(save_path, verts, faces, color)
except Exception as e:
    print(e)
    print("Can not create marching cubes at this time.")`

This is result 3D avatar of me.

image
image
image

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

1 participant