Při Definování model happyModel()
Implementuje vpřed množení pro binární klasifikaci model:
ZEROPAD2D -> CONV2D -> BATCHNORM -> RELU -> MAXPOOL -> ROZLOŽIT -> HUSTÁ
Všimněte si, že pro jednoduchost a třídění účely, budete hard-kód všechny hodnoty jako krok a jádro (filtr) velikostí. Normálně, funkce by měly brát tyto hodnoty jako parametry funkce.
model-TF Keras model (objekt obsahující informace pro celý tréninkový proces)
def happyModel():
model = tf.keras.Sequential(
[
## ZeroPadding2D with padding 3, input shape of 64 x 64 x 3
tfl.ZeroPadding2D(padding=(3,3), data_format=(64,64,3)),
## Conv2D with 32 7x7 filters and stride of 1
tfl.Conv2D(32, (7, 7), strides = (1, 1), name = 'conv0'),
## BatchNormalization for axis 3
tfl.BatchNormalization(axis = 3, name = 'bn0'),
## ReLU
tfl.Activation('relu'),
## Max Pooling 2D with default parameters
tfl.MaxPooling2D((2, 2), name='max_pool0'),
## Flatten layer
tfl.Flatten(),
## Dense layer with 1 unit for output & 'sigmoid' activation
tfl.Dense(1, activation='sigmoid', name='fc'),
# YOUR CODE STARTS HERE
# YOUR CODE ENDS HERE
]
)
return model
Vytvoření objektu z definice modelu:
happy_model = happyModel()
# Print a summary for each layer
for layer in summary(happy_model):
print(layer)
output = [['ZeroPadding2D', (None, 70, 70, 3), 0, ((3, 3), (3, 3))],
['Conv2D', (None, 64, 64, 32), 4736, 'valid', 'linear', 'GlorotUniform'],
['BatchNormalization', (None, 64, 64, 32), 128],
['ReLU', (None, 64, 64, 32), 0],
['MaxPooling2D', (None, 32, 32, 32), 0, (2, 2), (2, 2), 'valid'],
['Flatten', (None, 32768), 0],
['Dense', (None, 1), 32769, 'sigmoid']]
comparator(summary(happy_model), output)
Chybu jsem stále "AttributeError: 'tuple' objekt nemá žádný atribut 'nižší'"
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-50-f33284fd82fe> in <module>
----> 1 happy_model = happyModel()
2 # Print a summary for each layer
3 for layer in summary(happy_model):
4 print(layer)
5
<ipython-input-49-b5fc98b1ebba> in happyModel()
21
22 ## ZeroPadding2D with padding 3, input shape of 64 x 64 x 3
---> 23 tfl.ZeroPadding2D(padding=(3,3), data_format=(64,64,3)),
24
25 ## Conv2D with 32 7x7 filters and stride of 1
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/layers/convolutional.py in
__init__(self, padding, data_format, **kwargs)
2800 def __init__(self, padding=(1, 1), data_format=None, **kwargs):
2801 super(ZeroPadding2D, self).__init__(**kwargs)
-> 2802 self.data_format = conv_utils.normalize_data_format(data_format)
2803 if isinstance(padding, int):
2804 self.padding = ((padding, padding), (padding, padding))
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/utils/conv_utils.py in
normalize_data_format(value)
190 if value is None:
191 value = backend.image_data_format()
--> 192 data_format = value.lower()
193 if data_format not in {'channels_first', 'channels_last'}:
194 raise ValueError('The `data_format` argument must be one of '
AttributeError: 'tuple' object has no attribute 'lower'
Jaký je důvod za tím stojí? Může někdo mi navrhnout nějaké řešení! TIA