segmentation_models
segmentation_models copied to clipboard
AttributeError: 'Functional' object has no attribute 'loss_weights'
The code i used:
model = P['model'](P['backbone'], encoder_weights='imagenet', encoder_freeze = True)#, gn_groups = P['gn_groups'])
if P['use_reg']:
model = set_regularization(model, kernel_regularizer=P['reg_class'](P['reg_lambda']),
bias_regularizer = P['reg_class'](P['reg_lambda'])
)
dice = DiceCoefficient()
if P['mixed_precision']:
opt = keras.mixed_precision.LossScaleOptimizer(
keras.optimizers.Adam(learning_rate=P['LR']),
)
else:
opt = keras.optimizers.Adam(learning_rate=P['LR'])
loss = HybridLoss()
model.compile(optimizer = opt,
loss = loss, #tf.keras.losses.BinaryCrossentropy(),#'focal_tversky',
metrics=[dice, 'accuracy'])
model.fit() ...
set_trainable(model)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-27-271bafab9920> in <module>
109
110 # unfreeze model layers
--> 111 set_trainable(model)
112
113 ## Start training
~/software/anaconda3/envs/hk2/lib/python3.8/site-packages/segmentation_models/utils.py in set_trainable(model, recompile, **kwargs)
32 loss=model.loss,
33 metrics=model.metrics,
---> 34 loss_weights=model.loss_weights,
35 sample_weight_mode=model.sample_weight_mode,
36 weighted_metrics=model.weighted_metrics,
AttributeError: 'Functional' object has no attribute 'loss_weights'
same problem here. Any solution?
same problem
same problem. A quick fix is to pass recompile=False
, it's not ideal tho...
same problem.
The following seems to run, but is it recommended?
set_trainable(model, recompile=False)
model.compile(
model.optimizer,
loss=model.loss,
metrics=model.metrics,
loss_weights=None,
sample_weight_mode=None,
weighted_metrics=None,
)
@pace577 Yes. If you check the code of the set_trainable
method, that's what it does.