nkolot / GraphCMR

Repository for the paper "Convolutional Mesh Regression for Single-Image Human Shape Reconstruction"
BSD 3-Clause "New" or "Revised" License
425 stars 67 forks source link

Compute 'A', 'D', 'U' matrices #35

Open moondabaojian opened 4 years ago

moondabaojian commented 4 years ago

Hello! I want to try use other human template(SMPLX) in your work, I need precompuute 'A', 'D', 'U' matrices according this , so I test using the smpl template first, but I can't get the same result as you. Please point out my mistake, Thank you ! I changed part of the code of ‘coma’

from __future__ import print_function
import mesh_sampling
from psbody.mesh import Mesh, MeshViewer, MeshViewers
import numpy as np
import json
import os
import copy
import argparse
import pickle
import time

print("Loading data .. ")
reference_mesh_file = 'data/smpl_neutral_vertices.obj'
reference_mesh = Mesh(filename=reference_mesh_file)

ds_factors = [4,1]  # Sampling factor of the mesh at each stage of sampling
print("Generating Transform Matrices ..")

# Generates adjecency matrices A, downsampling matrices D, and upsamling matrices U by sampling
# the mesh 4 times. Each time the mesh is sampled by a factor of 4

M,A,D,U = mesh_sampling.generate_transform_matrices(reference_mesh, ds_factors)

print(type(A))

np.savez('mesh_downsampling_test.npz', A = A, D = D, U = U)
nkolot commented 4 years ago

How different are the 2 results?

moondabaojian commented 4 years ago

File size is different Screenshot from 2020-01-08 09-57-02

There are also some differences in the content of the file,I output the contents of the file with the following code

import sys
import numpy as np
from psbody.mesh import Mesh

data = np.load('mesh_downsampling_test.npz',encoding='latin1')
print(type(data['A_test']))

np.savetxt('out_A_test.txt',data['A_test'],fmt='%s')
np.savetxt('out_D_test.txt',data['D_test'],fmt='%s')
np.savetxt('out_U_test.txt',data['U_test'],fmt='%s')
#np.savetxt('out_F.txt',data['F'],fmt='%s')
#np.savetxt('out_M.txt',data['M'],fmt='%s')

output.tar.gz

moondabaojian commented 4 years ago

I'm sorry to disturb you. I hope you can give me a reply. Thank you very much

syenpark commented 4 years ago

Hi @moondabaojian, can you try ds_factors = [4, 4] instead of [4, 1] and get back to me? FYI, I used pytorch_coma to reproduce the work.

First of all, I checked the original mesh_downsampling.npz in GraphCMR/data and that is like following:

# default['A']
array([<6890x6890 sparse matrix of type '<class 'numpy.float64'>'
    with 41328 stored elements in Compressed Sparse Column format>,
       <1723x1723 sparse matrix of type '<class 'numpy.float64'>'
    with 10326 stored elements in Compressed Sparse Column format>,
       <431x431 sparse matrix of type '<class 'numpy.float64'>'
    with 2574 stored elements in Compressed Sparse Column format>],
      dtype=object)

# default['D']
array([<1723x6890 sparse matrix of type '<class 'numpy.float64'>'
    with 1723 stored elements in Compressed Sparse Column format>,
       <431x1723 sparse matrix of type '<class 'numpy.float64'>'
    with 431 stored elements in Compressed Sparse Column format>],
      dtype=object)

# default['U']
array([<6890x1723 sparse matrix of type '<class 'numpy.float64'>'
    with 20670 stored elements in Compressed Sparse Column format>,
       <1723x431 sparse matrix of type '<class 'numpy.float64'>'
    with 5169 stored elements in Compressed Sparse Column format>],
      dtype=object)

However, the new npz result after applying ds_factors = [4, 1] to basicModel_neutral_lbs_10_207_0_v1.0.0.pkl that we can download via ./fetch_data.sh is different. I suppose this lead to the different size that you mentioned.

# template['A']
array([<6890x6890 sparse matrix of type '<class 'numpy.float64'>'
    with 41328 stored elements in COOrdinate format>,
       <1723x1723 sparse matrix of type '<class 'numpy.float64'>'
    with 10326 stored elements in COOrdinate format>,
       <1723x1723 sparse matrix of type '<class 'numpy.float64'>'
    with 10326 stored elements in COOrdinate format>], dtype=object)

# template['D']
array([<1723x6890 sparse matrix of type '<class 'numpy.float64'>'
    with 1723 stored elements in COOrdinate format>,
       <1723x1723 sparse matrix of type '<class 'numpy.float64'>'
    with 1723 stored elements in COOrdinate format>], dtype=object)

# template['U']
array([<6890x1723 sparse matrix of type '<class 'numpy.float64'>'
    with 20670 stored elements in COOrdinate format>,
       <1723x1723 sparse matrix of type '<class 'numpy.float64'>'
    with 5169 stored elements in COOrdinate format>], dtype=object)

Each A, D, and U matrix size is different from the original .npz, so that I try making it the same by using ds_factors = [4, 4]. This produces the same matrix size like the below result.

# test['A']
array([<6890x6890 sparse matrix of type '<class 'numpy.float64'>'
    with 41328 stored elements in COOrdinate format>,
       <1723x1723 sparse matrix of type '<class 'numpy.float64'>'
    with 10326 stored elements in COOrdinate format>,
       <431x431 sparse matrix of type '<class 'numpy.float64'>'
    with 2574 stored elements in COOrdinate format>], dtype=object)

# test['D']
array([<1723x6890 sparse matrix of type '<class 'numpy.float64'>'
    with 1723 stored elements in COOrdinate format>,
       <431x1723 sparse matrix of type '<class 'numpy.float64'>'
    with 431 stored elements in COOrdinate format>], dtype=object)

# test['U']
rray([<6890x1723 sparse matrix of type '<class 'numpy.float64'>'
    with 20670 stored elements in COOrdinate format>,
       <1723x431 sparse matrix of type '<class 'numpy.float64'>'
    with 5169 stored elements in COOrdinate format>], dtype=object)

However, the inside of matrix result is slightly different. This makes me not certain I did in a correct way and curious the sentence in the paper;

subsample by 4 factor and upsample it again the original scale.

The above sentence seems to mean [4, 1] but [4, 4] gives me similar result. If @nkolot can help us, it will be very nice.

moondabaojian commented 4 years ago

Hello @syenpark , Thank you for your reply to this question. According to your suggestion, I tried using ds_factors = [4, 4] , Here are my results Screenshot from 2020-02-27 17-11-56 and output.tar.gz

I still haven't got the same result as the original one mesh_downsampling.npz. But as you suggest, we have at least the same matrix structure

syenpark commented 4 years ago

@moondabaojian, I suppose some format or header information of .npz leads to the slight different size that you point out. For instance, the discrepancy in the format such as Compressed Sparse Column format in the original and COOrdinate format in mine. This difference doesn't cause any issues when I run the pretrained model of this GitHub on my own mesh.