nfnets-keras
nfnets-keras copied to clipboard
Issues with initializing `StochasticDepth` Layer
Hi!
I am trying to have a look at the TensorFlow implementation of NFNet, and somehow got to fix the reference-before-assignment issue with some help from @prateekkrjain.
However, when I try to instantiate NFNetF0 as follows:
x = NFNetF0(num_classes = num_classes)(x)
the Python interpreter complains that it has an error as follows:
TypeError: in user code:
C:\Users\<myUserName>\NFNet\nfnets_keras\nfnet.py:143 call *
for i, block in enumerate(self.blocks): out, res_avg_var = block(out, training = training)
C:\Users\<myUserName>\NFNet\nfnets_keras\nfnet.py:200 call *
out = self.stoch_depth(out, training)
C:\Users\<myUserName>\NFNet\nfnets_keras\nfnet_layers.py:47 call *
r = tf.random.uniform(shape = [batch_size, 1, 1, 1], dtype = x.dtype)
C:\Users\<myUserName>\miniconda3\lib\site-packages\tensorflow\python\util\dispatch.py:201 wrapper **
return target(*args, **kwargs)
C:\Users\<myUserName>\miniconda3\lib\site-packages\tensorflow\python\ops\random_ops.py:289 random_uniform
shape = tensor_util.shape_tensor(shape)
C:\Users\<myUserName>\miniconda3\lib\site-packages\tensorflow\python\framework\tensor_util.py:1035 shape_tensor
return ops.convert_to_tensor(shape, dtype=dtype, name="shape")
C:\Users\<myUserName>\miniconda3\lib\site-packages\tensorflow\python\profiler\trace.py:163 wrapped
return func(*args, **kwargs)
C:\Users\<myUserName>\miniconda3\lib\site-packages\tensorflow\python\framework\ops.py:1540 convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
C:\Users\<myUserName>\miniconda3\lib\site-packages\tensorflow\python\framework\constant_op.py:339 _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
C:\Users\<myUserName>\miniconda3\lib\site-packages\tensorflow\python\framework\constant_op.py:264 constant
return _constant_impl(value, dtype, shape, name, verify_shape=False,
C:\Users\<myUserName>\miniconda3\lib\site-packages\tensorflow\python\framework\constant_op.py:281 _constant_impl
tensor_util.make_tensor_proto(
C:\Users\<myUserName>\miniconda3\lib\site-packages\tensorflow\python\framework\tensor_util.py:551 make_tensor_proto
raise TypeError("Failed to convert object of type %s to Tensor. "
TypeError: Failed to convert object of type <class 'tuple'> to Tensor. Contents: (None, 1, 1, 1). Consider casting elements to a supported type.
It seems like there is something wrong with the arguments being passed to tf.random.uniform()
function when initializing StochasticDepth
Layer. The batch_size
turns out to be None
.
Any ideas on how to fix this?
Note that I am using the latest version of Miniconda with Python 3.8, along with TensorFlow 2.4.1 on a Windows 10.
Did you ever managed to solve this?
@thrmotta Unfortunately, no...it has been about 3 months and still not a clear clue on why this is happening. :(
For the time being, I am checking with an alternative Tensorflow/Keras implementation of NFNet by @hoangthang1607, which can be accessed via following link: https://github.com/hoangthang1607/nfnets-Tensorflow-2
The alternative implementation seems to give me some hints on how the issue could be fixed, although it also seems to have some issues as well, such as "no inbound nodes" issue when attempting to use the network as base net for object detection.