bharat-b7 / MultiGarmentNetwork

Repo for "Multi-Garment Net: Learning to Dress 3D People from Images, ICCV'19"
282 stars 65 forks source link

In python3.5: tensorflow.python.framework.errors_impl.InvalidArgumentError: Value for attr 'Tshape' of float is not in the list of allowed values: int32, int64 #25

Closed Frank-Dz closed 4 years ago

Frank-Dz commented 4 years ago

Hi~ I make a py3(python3.5) version of MGN on my Ubuntu16.04. (I will explain at the end.) And successfully installed Mesh as well as Dirt. All necessary data are loaded. But When I ran the code, I got this error:

/home/frank/Desktop/mesh-py3/my_venv/bin/python /home/frank/PycharmProjects/MultiGarmentNetwork/test_network.py
/home/frank/Desktop/mesh-py3/my_venv/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/frank/Desktop/mesh-py3/my_venv/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/frank/Desktop/mesh-py3/my_venv/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/frank/Desktop/mesh-py3/my_venv/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/frank/Desktop/mesh-py3/my_venv/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/frank/Desktop/mesh-py3/my_venv/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
Using dirt renderer.
/home/frank/Desktop/mesh-py3/my_venv/lib/python3.5/site-packages/sklearn/utils/deprecation.py:144: FutureWarning: The sklearn.decomposition.pca module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.decomposition. Anything that cannot be imported from sklearn.decomposition is now part of the private API.
  warnings.warn(message, FutureWarning)
/home/frank/Desktop/mesh-py3/my_venv/lib/python3.5/site-packages/sklearn/base.py:318: UserWarning: Trying to unpickle estimator PCA from version 0.19.0 when using version 0.22.2.post1. This might lead to breaking code or invalid results. Use at your own risk.
  UserWarning)
2020-04-16 16:50:57.176351: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-04-16 16:50:57.305715: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:998] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-04-16 16:50:57.306421: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x8358d20 executing computations on platform CUDA. Devices:
2020-04-16 16:50:57.306434: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): GeForce RTX 2080, Compute Capability 7.5
2020-04-16 16:50:57.327431: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2592000000 Hz
2020-04-16 16:50:57.328297: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x83c3ea0 executing computations on platform Host. Devices:
2020-04-16 16:50:57.328314: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): <undefined>, <undefined>
2020-04-16 16:50:57.328520: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found device 0 with properties: 
name: GeForce RTX 2080 major: 7 minor: 5 memoryClockRate(GHz): 1.095
pciBusID: 0000:01:00.0
totalMemory: 7.77GiB freeMemory: 7.17GiB
2020-04-16 16:50:57.328529: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0
2020-04-16 16:50:57.329260: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-04-16 16:50:57.329267: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990]      0 
2020-04-16 16:50:57.329271: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0:   N 
2020-04-16 16:50:57.329409: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6979 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2080, pci bus id: 0000:01:00.0, compute capability: 7.5)
WARNING:tensorflow:From /home/frank/PycharmProjects/MultiGarmentNetwork/smpl/batch_lbs.py:53: div (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Deprecated in favor of operator or tf.math.divide.
2020-04-16 16:50:58.393397: I tensorflow/stream_executor/dso_loader.cc:152] successfully opened CUDA library libcublas.so.10.0 locally
Using latest checkpoint at saved_model/ckpt-26
WARNING:tensorflow:From /home/frank/Desktop/mesh-py3/my_venv/lib/python3.5/site-packages/tensorflow/python/ops/resource_variable_ops.py:642: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
Traceback (most recent call last):
  File "/home/frank/PycharmProjects/MultiGarmentNetwork/test_network.py", line 189, in <module>
    pred = get_results(m, dat)
  File "/home/frank/PycharmProjects/MultiGarmentNetwork/test_network.py", line 54, in get_results
    out = m([images, vertex_label, J_2d])
  File "/home/frank/Desktop/mesh-py3/my_venv/lib/python3.5/site-packages/tensorflow/python/keras/engine/base_layer.py", line 592, in __call__
    outputs = self.call(inputs, *args, **kwargs)
  File "/home/frank/PycharmProjects/MultiGarmentNetwork/network/base_network.py", line 338, in call
    garm_model_outputs = [fe(latent_code_offset_ShapeMerged) for fe in self.garmentModels]
  File "/home/frank/PycharmProjects/MultiGarmentNetwork/network/base_network.py", line 338, in <listcomp>
    garm_model_outputs = [fe(latent_code_offset_ShapeMerged) for fe in self.garmentModels]
  File "/home/frank/Desktop/mesh-py3/my_venv/lib/python3.5/site-packages/tensorflow/python/keras/engine/base_layer.py", line 592, in __call__
    outputs = self.call(inputs, *args, **kwargs)
  File "/home/frank/PycharmProjects/MultiGarmentNetwork/network/base_network.py", line 66, in call
    x = self.PCA_(pca_comp)
  File "/home/frank/Desktop/mesh-py3/my_venv/lib/python3.5/site-packages/tensorflow/python/keras/engine/base_layer.py", line 592, in __call__
    outputs = self.call(inputs, *args, **kwargs)
  File "/home/frank/PycharmProjects/MultiGarmentNetwork/network/custom_layers.py", line 33, in call
    return tf.reshape(tf.matmul(x, self.components) + self.mean, (-1, K.int_shape(self.mean)[0] / 3, 3))
  File "/home/frank/Desktop/mesh-py3/my_venv/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 7161, in reshape
    tensor, shape, name=name, ctx=_ctx)
  File "/home/frank/Desktop/mesh-py3/my_venv/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 7206, in reshape_eager_fallback
    ctx=_ctx, name=name)
  File "/home/frank/Desktop/mesh-py3/my_venv/lib/python3.5/site-packages/tensorflow/python/eager/execute.py", line 66, in quick_execute
    six.raise_from(core._status_to_exception(e.code, message), None)
  File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError: Value for attr 'Tshape' of float is not in the list of allowed values: int32, int64
    ; NodeDef: {{node Reshape}}; Op<name=Reshape; signature=tensor:T, shape:Tshape -> output:T; attr=T:type; attr=Tshape:type,default=DT_INT32,allowed=[DT_INT32, DT_INT64]> [Op:Reshape]

Process finished with exit code 1

To make a py3 version, what I have done is:

from

def call(self, (pose,betas,trans)):

to

def call(self, pose_betas_trans):
       pose, betas, trans =pose_betas_trans

Also:

def matmul((i, bb)):
        sp = tf.SparseTensor(indices[i, :, 1:], values[i], shape[1:])
        return i, tf.sparse_tensor_dense_matmul(sp, bb)
        _, p = tf.map_fn(matmul, (tf.range(num_b), b))
        return p

to

def matmul((i_bb)):
        i, bb = i_bb
        sp = tf.SparseTensor(indices[i, :, 1:], values[i], shape[1:])
        return i, tf.sparse_tensor_dense_matmul(sp, bb)
        _, p = tf.map_fn(matmul, (tf.range(num_b), b))
        return p

Above are all functions I modified.

(That's all. I also noticed someone using 2to3 to transfer, but I think the modifications described above are enough.)

Device: I only have one GPU, thus, all my device is gpu:0 The size is about 8GB.

Thanks in advance!

Plus, my pkgs are as follows:

Keras-Applications | 1.0.8 |  
Keras-Preprocessing | 1.1.0 |  
Markdown | 3.2.1 |  
Pillow | 7.1.1 |  
PyOpenGL | 3.1.5 |  
PyYAML | 5.3.1 |  
Werkzeug | 1.0.1 |  
absl-py | 0.9.0 |  
astor | 0.8.1 |  
chumpy | 0.69 |  
cycler | 0.10.0 |  
dirt | 0.3.0 |  
gast | 0.3.3 |  
grpcio | 1.28.1 |  
h5py | 2.10.0 |  
joblib | 0.14.1 |  
kiwisolver | 1.2.0 |  
matplotlib | 2.2.5 |  
mock | 3.0.5 |  
numpy | 1.18.2 |  
opencv-python | 4.2.0.34 |  
pip | 20.0.2 |  
pkg-resources | 0.0.0 |  
protobuf | 3.11.3 |  
psbody-mesh | 0.3 |  
pyparsing | 2.4.7 |  
python-dateutil | 2.8.1 |  
pytz | 2019.3 |  
pyzmq | 19.0.0 |  
scikit-learn | 0.22.2.post1 |  
scipy | 1.4.1 |  
setuptools | 46.1.3 |  
six | 1.14.0 |  
sklearn | 0.0 |  
tensorboard | 1.13.1 |  
tensorflow-estimator | 1.13.0 |  
tensorflow-gpu | 1.13.1 |  
termcolor | 1.1.0 |  
wheel | 0.34.2 |  
Qingcsai commented 4 years ago

It seems like to be the exact division problem caused by converting py2 to py3 from your bug report:

File "/home/frank/PycharmProjects/MultiGarmentNetwork/network/custom_layers.py", line 33, in call return tf.reshape(tf.matmul(x, self.components) + self.mean, (-1, K.int_shape(self.mean)[0] / 3, 3))

Value for attr 'Tshape' of float is not in the list of allowed values: int32, int64

So you should change some / to // to make sure exact division, which has different meaning between py3 and py2.

For example in file YOUR_PATH_TO_MGN/MultiGarmentNetwork/network/custom_layers.py there are two places you need to change like followings:

class PCA_(Layer):
    def __init__(self, components, mean, **kwargs):
        super(PCA_, self).__init__(**kwargs)
        self.components = tf.Variable(components, trainable = False)
        self.mean = tf.Variable(mean, trainable = False)
        ######### here
        self.output_dim = (K.int_shape(self.mean)[0] // 3, 3) 

    def build(self, input_shape):
        super(PCA_, self).build(input_shape)  # Be sure to call this at the end

    def call(self, x):
         ######### here
        return tf.reshape(tf.matmul(x, self.components) + self.mean, (-1, K.int_shape(self.mean)[0] // 3, 3))

    def compute_output_shape(self, input_shape):
        return (input_shape[0], self.output_dim[0], self.output_dim[1])

There are some others places you need to change / to // but I don't rermenber them all , may you should check it by yourself , good luck to you!

Frank-Dz commented 4 years ago

It seems like to be the exact division problem caused by converting py2 to py3 from your bug report:

File "/home/frank/PycharmProjects/MultiGarmentNetwork/network/custom_layers.py", line 33, in call return tf.reshape(tf.matmul(x, self.components) + self.mean, (-1, K.int_shape(self.mean)[0] / 3, 3))

Value for attr 'Tshape' of float is not in the list of allowed values: int32, int64

So you should change some / to // to make sure exact division, which has different meaning between py3 and py2.

For example in file YOUR_PATH_TO_MGN/MultiGarmentNetwork/network/custom_layers.py there are two places you need to change like followings:

class PCA_(Layer):
    def __init__(self, components, mean, **kwargs):
        super(PCA_, self).__init__(**kwargs)
        self.components = tf.Variable(components, trainable = False)
        self.mean = tf.Variable(mean, trainable = False)
        ######### here
        self.output_dim = (K.int_shape(self.mean)[0] // 3, 3) 

    def build(self, input_shape):
        super(PCA_, self).build(input_shape)  # Be sure to call this at the end

    def call(self, x):
         ######### here
        return tf.reshape(tf.matmul(x, self.components) + self.mean, (-1, K.int_shape(self.mean)[0] // 3, 3))

    def compute_output_shape(self, input_shape):
        return (input_shape[0], self.output_dim[0], self.output_dim[1])

There are some others places you need to change / to // but I don't rermenber them all , may you should check it by yourself , good luck to you!

Thanks! I make it! Thanks for your kind help and guidande! Yet, after fixing this problem, I met another one: https://github.com/bharat-b7/MultiGarmentNetwork/issues/26 Actually, I also tested on Python2.7 before with DIRT for py2.7 successfully installed. I also got this error (At first I think it is caused by python's version, that's why I choose py3.5. But now it comes again...).

Anyway, thank you again for your help! Best, Frank

AlyanQ commented 2 years ago

For future reference, had to change one extra line other than the 2 mentioned above, line 58 in file MGN/network/base_network.py self.reshape = Reshape((len(pca.mean_)/3, 3)) to self.reshape = Reshape((len(pca.mean_)//3, 3))