Code Monkey home page Code Monkey logo

Comments (12)

nixingyang avatar nixingyang commented on May 27, 2024 2

Hi,
I encountered a similar issue using TensorFlow 2.4.1.
Here is a minimal snippet to replicate it:

from tensorflow.keras.layers import Input
from tensorflow.keras.models import Model
from tf2cv.model_provider import get_model

raw_model = get_model(name="resnestabc14", pretrained=True)

# First case
input_tensor = Input(shape=(224, 224, 3), batch_size=64)
output_tensor = raw_model(input_tensor)
model = Model(inputs=input_tensor, outputs=output_tensor)

# Second case
input_tensor = Input(shape=(224, 224, 3))
output_tensor = raw_model(input_tensor)
model = Model(inputs=input_tensor, outputs=output_tensor)

The first case runs properly, while the second case crashes.
All the best.

from imgclsmob.

osmr avatar osmr commented on May 27, 2024

Could you show me a minimal script to reproduce the error?

from imgclsmob.

Mrmdzz avatar Mrmdzz commented on May 27, 2024

WARNING:tensorflow:Skipping loading of weights for layer output1 due to mismatch in shape ((2048, 5) vs (2048, 1000)).
WARNING:tensorflow:Skipping loading of weights for layer output1 due to mismatch in shape ((5,) vs (1000,)).
INFO:tensorflow:Error reported to Coordinator: in user code:
TypeError: in user code:

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:571 train_function  *
    outputs = self.distribute_strategy.run(
C:\ProgramData\Anaconda3\lib\site-packages\tf2cv\models\resnesta.py:314 call  *
    x = self.features(x, training=training)
C:\ProgramData\Anaconda3\lib\site-packages\tf2cv\models\common.py:2925 call  *
    x = block(x, training=training)
C:\ProgramData\Anaconda3\lib\site-packages\tf2cv\models\common.py:2925 call  *
    x = block(x, training=training)
C:\ProgramData\Anaconda3\lib\site-packages\tf2cv\models\resnesta.py:234 call  *
    x = self.body(x, training=training)
C:\ProgramData\Anaconda3\lib\site-packages\tf2cv\models\resnesta.py:131 call  *
    x = self.conv2(x, training=training)
C:\ProgramData\Anaconda3\lib\site-packages\tf2cv\models\common.py:2739 call  *
    x = self.att(x, training=training)
C:\ProgramData\Anaconda3\lib\site-packages\tf2cv\models\common.py:2624 call  *
    x = tf.reshape(x, shape=(batch, height, width, self.radix, channels // self.radix))
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\ops\array_ops.py:193 reshape  **
    result = gen_array_ops.reshape(tensor, shape, name)
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\ops\gen_array_ops.py:8087 reshape
    "Reshape", tensor=tensor, shape=shape, name=name)
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py:473 _apply_op_helper
    raise err
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py:470 _apply_op_helper
    preferred_dtype=default_dtype)
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py:1341 convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\constant_op.py:321 _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\constant_op.py:262 constant
    allow_broadcast=True)
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\constant_op.py:300 _constant_impl
    allow_broadcast=allow_broadcast))
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\tensor_util.py:547 make_tensor_proto
    "supported type." % (type(values), values))

TypeError: Failed to convert object of type <class 'tuple'> to Tensor. Contents: (None, 128, 128, 2, 64). Consider casting elements to a supported type.

from imgclsmob.

Mrmdzz avatar Mrmdzz commented on May 27, 2024

minimal script:
model = tf2cv_get_model("resnesta50", pretrained=True, data_format="channels_last")
optimizer = tfa.optimizers.Lookahead(tfa.optimizers.RectifiedAdam(learning_rate=LR))
model.compile(...)
model.fit(...)

from imgclsmob.

osmr avatar osmr commented on May 27, 2024

Do you use a tf2cv pip package? What version is it?
Are you training other models with the same script?

from imgclsmob.

Mrmdzz avatar Mrmdzz commented on May 27, 2024

Is the latest version
Default used in the last 2-3 days pip install tf2cv

from imgclsmob.

osmr avatar osmr commented on May 27, 2024

Sorry. I can't reproduce your case using this description. It could be because of the different versions of TF/Keras or because I doesn't train the net with the fit function. I could suggest the following course of action: Please make a private repository containing minimal working code that reproduces the bug. In the readme, describe where to download the dataset. Add me to the repository. I'll debug the code and localize the error.

from imgclsmob.

Mrmdzz avatar Mrmdzz commented on May 27, 2024

I'll try another version TF/Keras.Which version of TF / keras is suitable for this model library?

from imgclsmob.

osmr avatar osmr commented on May 27, 2024

Theoretically any. Now I have TF 2.4.0 and Keras 2.3.1.

from imgclsmob.

osmr avatar osmr commented on May 27, 2024

Please test the effect of the last commit in the repository.

from imgclsmob.

Mrmdzz avatar Mrmdzz commented on May 27, 2024

thanks

from imgclsmob.

nixingyang avatar nixingyang commented on May 27, 2024

Thanks for the quick patch. The updated code works as expected.

from imgclsmob.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.