question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ConvNeXt model does not work with custom input tensors

See original GitHub issue

Please 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?

Contributing.

  • 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:closed
  • Created 10 months ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
djpetticommented, Nov 8, 2022

Hi @tilakrayal, it looks like this is because that notebook is using TF 2.9. convnext was only added in 2.10.

0reactions
google-ml-butler[bot]commented, Nov 8, 2022

Are you satisfied with the resolution of your issue? Yes No

Read more comments on GitHub >

github_iconTop Results From Across the Web

ConvNeXT - Hugging Face
The ConvNeXT model was proposed in A ConvNet for the 2020s by Zhuang Liu, Hanzi Mao, ... If not provided, it will be...
Read more >
Try out ConvNeXt in Keras! - Research & Models
Serializing to h5 weights might not be possible since the model has a custom layer that does not override get_config() . It's an...
Read more >
torch.nn.LayerNorm support for arbitrary axis in order to allow ...
If the input is NCHW tensor (default layout) it requires explicit NHWC ... a custom LayerNorm version in the ConvNext model) #76012. Open....
Read more >
ConvNext Transfer Learning in Pytorch (17.45) - Kaggle
A custom pytorch dataset class is implemented to attach scores to each image file, as well as the annotations. · The model is...
Read more >
ConvNeXt torchvision - specify input channels - Stack Overflow
You can rewrite the whole input layer, model._modules["features"][0][0] is nn.Conv2d(3, 96, kernel_size=(4, 4), stride=(4, 4)).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found