MMdnn icon indicating copy to clipboard operation
MMdnn copied to clipboard

AttributeError: 'NoneType' object has no attribute '_inbound_nodes'

Open waqaskayani opened this issue 5 years ago • 3 comments

Platform: Ubuntu 18.04.3 LTS

Python version: 3.6.5

Source framework with version: PyTorch 0.4.0

Destination framework with version: Keras 2.3.1

Pre-trained model path: Model

Running scripts: python -m mmdnn.conversion.examples.keras.imagenet_test -n keras_code_snippet.py -w test.npy --dump keras_model.h5

Thank you for this nice repo. I am trying to convert a small PyTorch model to Keras. It is successfully converted into IR representation i.e. when I run the following command: mmtoir -f pytorch -d test --inputShape 1,150,3 -n test.pth

It outputs .json, .pb and .npy files. And as mentioned in the documentation, there are further 2 steps.

  1. Creating keras_code_snippet.py, which is also created using the following command: mmtocode -f keras --IRModelPath test.pb --IRWeightPath test.npy --dstModelPath keras_code_snippet.py

  2. But finally for generating Keras model, I've been trying two different commands. The given one in documentation is (replacing file names with local names): python -m mmdnn.conversion.examples.keras.imagenet_test -n keras_code_snippet.py -w test.npy --dump keras_model.h5

    And the other: mmtomodel -f keras -in keras_code_snippet.py -iw test.npy -o keras_model

Both give the following error:

2020-01-14 16:59:06.904022: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-01-14 16:59:06.908270: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcuda.so.1
2020-01-14 16:59:06.986419: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] 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-01-14 16:59:06.986822: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5625e00fa030 executing computations on platform CUDA. Devices:
2020-01-14 16:59:06.986839: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): GeForce GTX 1050 Ti, Compute Capability 6.1
2020-01-14 16:59:07.005012: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2199995000 Hz
2020-01-14 16:59:07.006160: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5625e0571340 executing computations on platform Host. Devices:
2020-01-14 16:59:07.006223: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
2020-01-14 16:59:07.006541: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] 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-01-14 16:59:07.007142: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties: 
name: GeForce GTX 1050 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.62
pciBusID: 0000:01:00.0
2020-01-14 16:59:07.007386: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Could not dlopen library 'libcudart.so.10.0'; dlerror: libcudart.so.10.0: cannot open shared object file: No such file or directory
2020-01-14 16:59:07.007555: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Could not dlopen library 'libcublas.so.10.0'; dlerror: libcublas.so.10.0: cannot open shared object file: No such file or directory
2020-01-14 16:59:07.007712: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Could not dlopen library 'libcufft.so.10.0'; dlerror: libcufft.so.10.0: cannot open shared object file: No such file or directory
2020-01-14 16:59:07.007866: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Could not dlopen library 'libcurand.so.10.0'; dlerror: libcurand.so.10.0: cannot open shared object file: No such file or directory
2020-01-14 16:59:07.008021: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Could not dlopen library 'libcusolver.so.10.0'; dlerror: libcusolver.so.10.0: cannot open shared object file: No such file or directory
2020-01-14 16:59:07.008175: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Could not dlopen library 'libcusparse.so.10.0'; dlerror: libcusparse.so.10.0: cannot open shared object file: No such file or directory
2020-01-14 16:59:07.012256: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudnn.so.7
2020-01-14 16:59:07.012274: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1663] Cannot dlopen some GPU libraries. Skipping registering GPU devices...
2020-01-14 16:59:07.012290: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-01-14 16:59:07.012296: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187]      0 
2020-01-14 16:59:07.012301: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0:   N 
2020-01-14 16:59:07.022135: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set.  If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU.  To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.
WARNING:tensorflow:From /home/user/anaconda3/envs/dummyEnv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:4070: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.

WARNING:tensorflow:From /home/user/anaconda3/envs/dummyEnv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:4074: The name tf.nn.avg_pool is deprecated. Please use tf.nn.avg_pool2d instead.

Traceback (most recent call last):
  File "/home/user/anaconda3/envs/dummyEnv/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/user/anaconda3/envs/dummyEnv/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/user/anaconda3/envs/dummyEnv/lib/python3.6/site-packages/mmdnn/conversion/examples/keras/imagenet_test.py", line 157, in <module>
    tester = TestKeras()
  File "/home/user/anaconda3/envs/dummyEnv/lib/python3.6/site-packages/mmdnn/conversion/examples/keras/imagenet_test.py", line 31, in __init__
    self.model = self.MainModel.KitModel(self.args.w)
  File "keras_code_snippet.py", line 79, in KitModel
    model           = Model(inputs = [input], outputs = [reducedndepthwisenseparablenconvnLinearndense2n47])
  File "/home/user/anaconda3/envs/dummyEnv/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "/home/user/anaconda3/envs/dummyEnv/lib/python3.6/site-packages/keras/engine/network.py", line 94, in __init__
    self._init_graph_network(*args, **kwargs)
  File "/home/user/anaconda3/envs/dummyEnv/lib/python3.6/site-packages/keras/engine/network.py", line 241, in _init_graph_network
    self.inputs, self.outputs)
  File "/home/user/anaconda3/envs/dummyEnv/lib/python3.6/site-packages/keras/engine/network.py", line 1434, in _map_graph_network
    tensor_index=tensor_index)
  File "/home/user/anaconda3/envs/dummyEnv/lib/python3.6/site-packages/keras/engine/network.py", line 1421, in build_map
    node_index, tensor_index)
  File "/home/user/anaconda3/envs/dummyEnv/lib/python3.6/site-packages/keras/engine/network.py", line 1421, in build_map
    node_index, tensor_index)
  File "/home/user/anaconda3/envs/dummyEnv/lib/python3.6/site-packages/keras/engine/network.py", line 1421, in build_map
    node_index, tensor_index)
  File "/home/user/anaconda3/envs/dummyEnv/lib/python3.6/site-packages/keras/engine/network.py", line 1393, in build_map
    node = layer._inbound_nodes[node_index]
AttributeError: 'NoneType' object has no attribute '_inbound_nodes'

Could you please explain what the error means? And how it can be resolved. Thanks.

waqaskayani avatar Jan 14 '20 12:01 waqaskayani

Have the same issue after manually changing


 data= layers.Input(name = 'data', shape = (112, 112, 3,) )
 # The following line throws could not find minusscalar0_second
 minusscalar0    = my_sub()(data, minusscalar0_second)
 mulscalar0      = mul_constant(weight_factor=None, layer_name= minusscalar0)

to :

    data = layers.Input(name = 'data', shape = (112, 112, 3,) )
    minusscalar0_second = tf.constant(weights_dict['minusscalar0_second']['value'], dtype=tf.float32, name='minusscalar0_second')
    mulscalar0_second = tf.constant(weights_dict['mulscalar0_second']['value'], dtype=tf.float32, name='mulscalar0_second')
    minusscalar0    = data - minusscalar0_second
    mulscalar0      = minusscalar0 * mulscalar0_second

by cheating from the TF generated file.

It blows up at :

File "k_model.py", line 350, in KitModel model = Model(inputs = data, outputs = fc1)

Also the TF conversion works.

mjsML avatar Feb 12 '20 17:02 mjsML

After reading this This issue I figured out that everything needs to be a keras Layer so I changed those lines to :

    minusscalar0_second = K.constant(weights_dict['minusscalar0_second']['value'], name='minusscalar0_second')
    mulscalar0_second = K.constant(weights_dict['mulscalar0_second']['value'], name='mulscalar0_second')
    data = layers.Input(name='data', shape=(112, 112, 3,))
    minusscalar0 = my_sub()([data, minusscalar0_second])
    mulscalar0 = mul_constant(weight_factor=mulscalar0_second, layer_name=minusscalar0)

Yet still facing the same error ... the generated file with all the layers is hard to go through line by line to figure out which layer is not making Keras happy :(

mjsML avatar Feb 12 '20 18:02 mjsML

After reading this This issue I figured out that everything needs to be a keras Layer so I changed those lines to :

    minusscalar0_second = K.constant(weights_dict['minusscalar0_second']['value'], name='minusscalar0_second')
    mulscalar0_second = K.constant(weights_dict['mulscalar0_second']['value'], name='mulscalar0_second')
    data = layers.Input(name='data', shape=(112, 112, 3,))
    minusscalar0 = my_sub()([data, minusscalar0_second])
    mulscalar0 = mul_constant(weight_factor=mulscalar0_second, layer_name=minusscalar0)

Yet still facing the same error ... the generated file with all the layers is hard to go through line by line to figure out which layer is not making Keras happy :(

Facing the same issue ,did you find any solution ?

ansha-kamath avatar May 16 '20 12:05 ansha-kamath