francismontalbo / fused-densenet-tiny

A novel approach in training a DenseNet model for diagnosing COVID-19 Chest X-Rays.
https://francismontalbo.github.io
30 stars 5 forks source link

# DenseNet121-B #1

Open pavangarlapati97 opened 3 years ago

pavangarlapati97 commented 3 years ago

I've Got This Error Can You Please help me

AttributeError Traceback (most recent call last) /opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in setattr(self, name, value) 2828 try: -> 2829 super(tracking.AutoTrackable, self).setattr(name, value) 2830 except AttributeError:

AttributeError: can't set attribute

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)

in 16 17 #GENERATE THE MODEL ---> 18 densenet_tiny_B = densenet_tiny_B_builder(model_input) 19 20 #PLOT THE MODEL STRUCTURE in densenet_tiny_B_builder(model_input) 8 for layer in densenet_tiny_B_builder.layers: 9 layer.trainable = True ---> 10 layer.name = layer.name + str("_mirror") 11 12 #MODEL TRUNCATION /opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in __setattr__(self, name, value) 2832 ('Can\'t set the attribute "{}", likely because it conflicts with ' 2833 'an existing read-only @property of the object. Please choose a ' -> 2834 'different name.').format(name)) 2835 return 2836 AttributeError: Can't set the attribute "name", likely because it conflicts with an existing read-only @property of the object. Please choose a different name.
francismontalbo commented 3 years ago

Create the environment on Python 3.5 my friend if you want to try it fast.

I will update the code soon for newer versions of Python. Just create a new environment first with Python 3.5 then install the requirements :)

On Fri, Apr 16, 2021 at 5:52 PM pavangarlapati97 @.***> wrote:

I've Got This Error Can You Please help me AttributeError Traceback (most recent call last) /opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in setattr(self, name, value) 2828 try: -> 2829 super(tracking.AutoTrackable, self).setattr(name, value) 2830 except AttributeError:

AttributeError: can't set attribute

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last) in 16 17 #GENERATE THE MODEL ---> 18 densenet_tiny_B = densenet_tiny_B_builder(model_input) 19 20 #PLOT THE MODEL STRUCTURE

in densenet_tiny_B_builder(model_input) 8 for layer in densenet_tiny_B_builder.layers: 9 layer.trainable = True ---> 10 layer.name = layer.name + str("_mirror") 11 12 #MODEL TRUNCATION

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in setattr(self, name, value) 2832 ('Can't set the attribute "{}", likely because it conflicts with ' 2833 'an existing read-only @Property https://github.com/Property of the object. Please choose a ' -> 2834 'different name.').format(name)) 2835 return 2836

AttributeError: Can't set the attribute "name", likely because it conflicts with an existing read-only @Property https://github.com/Property of the object. Please choose a different name.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/francismontalbo/fused-densenet-tiny/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/APU4T5XXUAYLUCFCRVKPPV3TJABR7ANCNFSM43BGKAZQ .

pavangarlapati97 commented 3 years ago

Sir, I'm Using Kaggle Kernals to work with..

francismontalbo commented 3 years ago

There is a work around you can use the get_layer function and grab the layers of the B model then change the names of its layers. You cannot fuse them if the layer names are the same.

On Fri, Apr 16, 2021 at 9:52 PM pavangarlapati97 @.***> wrote:

Sir, I'm Using Kaggle Kernals to work with..

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/francismontalbo/fused-densenet-tiny/issues/1#issuecomment-821189921, or unsubscribe https://github.com/notifications/unsubscribe-auth/APU4T5RXZ2M6YOQM4LKQ573TJA5YVANCNFSM43BGKAZQ .

emukoya commented 3 years ago

Getting this error "ValueError: The name "conv1/conv" is used 2 times in the model. All layer names should be unique. " The whole error looks like this "ValueError Traceback (most recent call last)

in 11 12 #istantitate the ensemble model and report the summary ---> 13 fused_densenet_tiny = fused_densenet_tiny(models,model_input) 14 15 print() in fused_densenet_tiny(models, model_input) 7 y = Dropout(0.5)(y) 8 prediction = Dense(num_classes,activation='softmax', name='Softmax_Classifier')(y) ----> 9 model = Model(model_input, prediction, name='fused_densenet_tiny') 10 return model 11 ~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py in __new__(cls, *args, **kwargs) 240 # Functional model 241 from tensorflow.python.keras.engine import functional # pylint: disable=g-import-not-at-top --> 242 return functional.Functional(*args, **kwargs) 243 else: 244 return super(Model, cls).__new__(cls, *args, **kwargs) ~\anaconda3\lib\site-packages\tensorflow\python\training\tracking\base.py in _method_wrapper(self, *args, **kwargs) 455 self._self_setattr_tracking = False # pylint: disable=protected-access 456 try: --> 457 result = method(self, *args, **kwargs) 458 finally: 459 self._self_setattr_tracking = previous_value # pylint: disable=protected-access ~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\functional.py in __init__(self, inputs, outputs, name, trainable) 113 # 'arguments during initialization. Got an unexpected argument:') 114 super(Functional, self).__init__(name=name, trainable=trainable) --> 115 self._init_graph_network(inputs, outputs) 116 117 @trackable.no_automatic_dependency_tracking ~\anaconda3\lib\site-packages\tensorflow\python\training\tracking\base.py in _method_wrapper(self, *args, **kwargs) 455 self._self_setattr_tracking = False # pylint: disable=protected-access 456 try: --> 457 result = method(self, *args, **kwargs) 458 finally: 459 self._self_setattr_tracking = previous_value # pylint: disable=protected-access ~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\functional.py in _init_graph_network(self, inputs, outputs) 188 189 # Keep track of the network's nodes and layers. --> 190 nodes, nodes_by_depth, layers, _ = _map_graph_network( 191 self.inputs, self.outputs) 192 self._network_nodes = nodes ~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\functional.py in _map_graph_network(inputs, outputs) 939 for name in all_names: 940 if all_names.count(name) != 1: --> 941 raise ValueError('The name "' + name + '" is used ' + 942 str(all_names.count(name)) + ' times in the model. ' 943 'All layer names should be unique.') ValueError: The name "conv1/conv" is used 2 times in the model. All layer names should be unique. What could I be missing? please help
francismontalbo commented 3 years ago

Getting this error "ValueError: The name "conv1/conv" is used 2 times in the model. All layer names should be unique. " The whole error looks like this "ValueError Traceback (most recent call last) in 11 12 #istantitate the ensemble model and report the summary ---> 13 fused_densenet_tiny = fused_densenet_tiny(models,model_input) 14 15 print()

in fused_densenet_tiny(models, model_input) 7 y = Dropout(0.5)(y) 8 prediction = Dense(num_classes,activation='softmax', name='Softmax_Classifier')(y) ----> 9 model = Model(model_input, prediction, name='fused_densenet_tiny') 10 return model 11

~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py in new(cls, *args, kwargs) 240 # Functional model 241 from tensorflow.python.keras.engine import functional # pylint: disable=g-import-not-at-top --> 242 return functional.Functional(*args, kwargs) 243 else: 244 return super(Model, cls).new*(cls, args, kwargs)

~\anaconda3\lib\site-packages\tensorflow\python\training\tracking\base.py in _method_wrapper(self, *args, *kwargs) 455 self._self_setattr_tracking = False # pylint: disable=protected-access 456 try: --> 457 result = method(self, args, **kwargs) 458 finally: 459 self._self_setattr_tracking = previous_value # pylint: disable=protected-access

~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\functional.py in init(self, inputs, outputs, name, trainable) 113 # 'arguments during initialization. Got an unexpected argument:') 114 super(Functional, self).init(name=name, trainable=trainable) --> 115 self._init_graph_network(inputs, outputs) 116 117 @trackable.no_automatic_dependency_tracking

~\anaconda3\lib\site-packages\tensorflow\python\training\tracking\base.py in _method_wrapper(self, *args, *kwargs) 455 self._self_setattr_tracking = False # pylint: disable=protected-access 456 try: --> 457 result = method(self, args, **kwargs) 458 finally: 459 self._self_setattr_tracking = previous_value # pylint: disable=protected-access

~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\functional.py in _init_graph_network(self, inputs, outputs) 188 189 # Keep track of the network's nodes and layers. --> 190 nodes, nodes_bydepth, layers, = _map_graph_network( 191 self.inputs, self.outputs) 192 self._network_nodes = nodes

~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\functional.py in _map_graph_network(inputs, outputs) 939 for name in all_names: 940 if all_names.count(name) != 1: --> 941 raise ValueError('The name "' + name + '" is used ' + 942 str(all_names.count(name)) + ' times in the model. ' 943 'All layer names should be unique.')

ValueError: The name "conv1/conv" is used 2 times in the model. All layer names should be unique.

What could I be missing? please help

My friend. You just have to rename the layers properly and make sure there are no similar names for the layers.

Use the following code for the builders.

USE THIS FOR THE BUILDER A

for layer in densenet_tiny_A_builder.layers:
      layer.trainable = True
      layer._name = layer.name + str("_mirror")

USE THIS FOR THE BUILDER B

for layer in densenet_tiny_B_builder.layers:
      layer.trainable = True
      layer._name = layer.name + str("_mirror")

They will rename all the layers within the network. This happens because they are still within the same pipeline and extract features. This also happens because of the updated dependencies. The previous layer.name should be layer._name You may refer to the paper as well. Thank you. I hope this helps.

https://www.sciencedirect.com/science/article/pii/S2215016121002016

https://www.sciencedirect.com/science/article/abs/pii/S1746809421001804