ConvNeXt model does not work with custom input tensors
See original GitHub issuePlease go to TF Forum for help and support:
https://discuss.tensorflow.org/tag/keras
If you open a GitHub issue, here is our policy:
It must be a bug, a feature request, or a significant problem with the documentation (for small docs fixes please send a PR instead). The form below must be filled out.
Here’s why we have that policy:.
Keras developers respond to issues. We want to focus on work that benefits the whole community, e.g., fixing bugs and adding features. Support only helps individuals. GitHub also notifies thousands of people when issues are filed. We want them to see you communicating an interesting problem, rather than being redirected to Stack Overflow.
System information.
- Have I written custom code (as opposed to using a stock example script provided in Keras): Yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 20.04
- TensorFlow installed from (source or binary): Binary
- TensorFlow version (use command below): 2.10.0
- Python version: 3.8.6
- Bazel version (if compiling from source): N/A
- GPU model and memory: Nvidia GTX 1080 Ti
- Exact command to reproduce:
import tensorflow as tf
images = tf.keras.layers.Input(shape=(420, 420, 3), name="frame")
net = tf.keras.applications.convnext.ConvNeXtSmall(include_top=False, weights="imagenet", input_tensor=images)
Describe the problem.
I expect the above code to work. In fact, very similar code works with efficientnet_v2
, but not with convnext
. In practice, I get the following error:
Traceback (most recent call last):
File "/home/daniel/git/cotton_flower_mot/.venv/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3398, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-7-40e50819ba7b>", line 1, in <cell line: 1>
net = tf.keras.applications.convnext.ConvNeXtSmall(include_top=False,
File "/home/daniel/git/cotton_flower_mot/.venv/lib/python3.8/site-packages/keras/applications/convnext.py", line 610, in ConvNeXtSmall
return ConvNeXt(
File "/home/daniel/git/cotton_flower_mot/.venv/lib/python3.8/site-packages/keras/applications/convnext.py", line 461, in ConvNeXt
x = PreStem(name=model_name)(x)
File "/home/daniel/git/cotton_flower_mot/.venv/lib/python3.8/site-packages/keras/applications/convnext.py", line 313, in apply
x = layers.Normalization(
File "/home/daniel/git/cotton_flower_mot/.venv/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/home/daniel/git/cotton_flower_mot/.venv/lib/python3.8/site-packages/keras/layers/preprocessing/normalization.py", line 166, in build
raise ValueError(
ValueError: Normalization only accepts a single input. If you are passing a python list or tuple as a single input, please convert to a numpy array or `tf.Tensor`.
It appears that the problem is here. According to the docs, get_source_inputs
always returns a list, but then that list is passed directly as the input for a Normalization
error. I’m not precisely sure what the purpose of this operation is. (I don’t see a similar call to get_source_inputs
in efficientnet_v2
.) Shouldn’t we be passing img_input
directly to the Normalization
layer?
- Do you want to contribute a PR? (yes/no): I can, but I’m not sure I understand the problem well enough.
- If yes, please read this page for instructions
- Briefly describe your candidate solution(if contributing):
Standalone code to reproduce the issue.
(Copying from above)
import tensorflow as tf
images = tf.keras.layers.Input(shape=(420, 420, 3), name="frame")
net = tf.keras.applications.convnext.ConvNeXtSmall(include_top=False, weights="imagenet", input_tensor=images)
Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Colab/Jupyter/any notebook.
Source code / logs.
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached. Try to provide a reproducible test case that is the bare minimum necessary to generate the problem.
Issue Analytics
- State:
- Created 10 months ago
- Comments:5
Top GitHub Comments
Hi @tilakrayal, it looks like this is because that notebook is using TF 2.9.
convnext
was only added in 2.10.Are you satisfied with the resolution of your issue? Yes No