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.

AttributeError: 'Model' object has no attribute 'weighted_metrics' while calling set_trainable

See original GitHub issue

Hi,

while calling set_trainable(true) to fine tune a model (following the tutorial here: https://segmentation-models.readthedocs.io/en/latest/tutorial.html#fine-tuning ), I get the following error:

  File "experiment0.py", line 75, in run_exp
    set_trainable(model)
  File "/home/benq/anaconda3/envs/tf2/lib/python3.7/site-packages/segmentation_models/utils.py", line 36, in set_trainable
    weighted_metrics=model.weighted_metrics,
AttributeError: 'Model' object has no attribute 'weighted_metrics'

the model is Unet with resnet34 backbone, running on tensorflow 2.0. The first call tomodel.fit_generator works without issue.

Any idea?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
marcomameli1992commented, Apr 16, 2020

I try your code and before yesterday it works, but yesterday when I try to recompile the network I obtain the error reported here, more precisely I have:

Traceback (most recent call last): File “training.py”, line 83, in <module> sm.utils.set_trainable(model=model, recompile=True) File “/usr/local/lib/python3.6/dist-packages/segmentation_models/utils.py”, line 36, in set_trainable weighted_metrics=model.weighted_metrics, AttributeError: ‘Model’ object has no attribute ‘weighted_metrics’

The same error of benqua, but I use Tensorflow-gpu 1.13.2 and I try tensorflow-gpu 1.15.0 and after the deletion of the

weighted_metrics=model.weighted_metrics

the result is an error on fit_generator:

Epoch 1/80 Traceback (most recent call last): File “training.py”, line 120, in <module> validation_steps=len(valid_dataloader) File “/usr/local/lib/python3.6/dist-packages/keras/legacy/interfaces.py”, line 91, in wrapper return func(*args, **kwargs) File “/usr/local/lib/python3.6/dist-packages/keras/engine/training.py”, line 1732, in fit_generator initial_epoch=initial_epoch) File “/usr/local/lib/python3.6/dist-packages/keras/engine/training_generator.py”, line 220, in fit_generator reset_metrics=False) File “/usr/local/lib/python3.6/dist-packages/keras/engine/training.py”, line 1514, in train_on_batch outputs = self.train_function(ins) File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/backend.py”, line 3076, in call run_metadata=self.run_metadata) File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py”, line 1439, in call run_metadata_ptr) File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/errors_impl.py”, line 528, in exit c_api.TF_GetCode(self.status.status)) tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor ‘softmax_target’ with dtype float and shape [?,?,?,?] [[{{node softmax_target}}]] [[{{node Mean_1}}]]

I don’t know how to solve this issue. Can you help me, please?

1reaction
systemallicacommented, Apr 27, 2020

I’m facing the same error, is there a known fix? @qubvel

Read more comments on GitHub >

github_iconTop Results From Across the Web

'Model' object has no attribute '_distribution_strategy' - Stack ...
I found the answer, fortunately. I forgot to call the superclass of the tensorflow keras model; I just had to add super(MyModel, self)....
Read more >
Attributeerror: 'Model' Object Has No Attribute 'Epoch' - Keras
AttributeError : 'list' object has no attribute 'size' with HuggingFace model ... object has no attribute 'weightedmetrics' while calling settrainable #215.
Read more >
Model object has no attribute '_is_graph_network', when I try ...
Model object has no attribute '_is_graph_network', when I try to save my model to tflite. Tensorflow version - 1.14.0 Python version - 3.7.5....
Read more >
PYTHON : AttributeError: 'module' object has no attribute 'model'
PYTHON : AttributeError : 'module' object has no attribute ' model ' [ Gift : Animated Search Engine : https://www.hows.tech/p/recommended.html ] ...
Read more >
Problem with load trained model - Part 1 (2019) - Fast.ai forums
But, when I run to load, I got this issue: AttributeError: 'Conv2d' object has no attribute 'padding_mode'. I tried updating the version, ...
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