AttributeError: 'Tuple' Objekt hat kein Attribut 'as_list' bei Verwendung von tf.keras.input
Posted: 04 Feb 2025, 12:28
Ich versuche, ResNet3D aus TensorFlow-Models Bibliothek zu verwenden, aber ich erhalte diesen seltsamen Fehler, wenn ich versuche, den Block
auszuführen
Ich habe versucht, die Eingabe an das Form als Liste weiterzugeben, aber immer noch den gleichen Fehler zu erhalten.
auszuführen
Code: Select all
def create_model():
base_model = tfm.vision.backbones.ResNet3D(model_id = 50,
temporal_strides= [3,3,3,3],
temporal_kernel_sizes = [(5,5,5),(5,5,5,5),(5,5,5,5,5,5),(5,5,5)],
input_specs=tf.keras.layers.InputSpec(shape=(None, None, IMG_SIZE, IMG_SIZE, 3))
)
# Unfreeze the base model layers
base_model.trainable = True
# Create the model
inputs = Input(shape=[None, None, IMG_SIZE, IMG_SIZE, 3])
x = base_model(inputs) # B,1,7,7,2048
x = GlobalAveragePooling3D(data_format="channels_last", keepdims=False)(x)
x = Dense(1024, activation='relu')(x)
x = tf.keras.layers.Dropout(0.3)(x) # Add dropout to prevent overfitting
outputs = Dense(NUM_CLASSES, activation='softmax')(x)
model = Model(inputs, outputs)
# Compile the model with class weights
optimizer = AdamW(learning_rate=1e-4, weight_decay=1e-5)
model.compile(
optimizer=optimizer,
loss='sparse_categorical_crossentropy',
metrics=['accuracy', tf.keras.metrics.AUC()]
)
return model
# Create and display model
model = create_model()
model.summary()
< /code>
Wenn ich dies ausführe, erhalte ich den Fehler unten: < /p>
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
in ()
37
38 # Create and display model
---> 39 model = create_model()
40 model.summary()
in create_model()
18 # Create the model
19 inputs = Input(shape=(None, None, IMG_SIZE, IMG_SIZE, 3))
---> 20 x = base_model(inputs) # B,1,7,7,2048
21 x = GlobalAveragePooling3D(data_format="channels_last", keepdims=False)(x)
22 x = Dense(1024, activation='relu')(x)
/usr/local/lib/python3.10/dist-packages/tf_keras/src/utils/traceback_utils.py in error_handler(*args, **kwargs)
59 def error_handler(*args, **kwargs):
60 if not tf.debugging.is_traceback_filtering_enabled():
---> 61 return fn(*args, **kwargs)
62
63 filtered_tb = None
/usr/local/lib/python3.10/dist-packages/tf_keras/src/engine/training.py in __call__(self, *args, **kwargs)
586 layout_map_lib._map_subclass_model_variable(self, self._layout_map)
587
--> 588 return super().__call__(*args, **kwargs)
589
590 @doc_controls.doc_in_current_and_subclasses
/usr/local/lib/python3.10/dist-packages/tf_keras/src/utils/traceback_utils.py in error_handler(*args, **kwargs)
59 def error_handler(*args, **kwargs):
60 if not tf.debugging.is_traceback_filtering_enabled():
---> 61 return fn(*args, **kwargs)
62
63 filtered_tb = None
/usr/local/lib/python3.10/dist-packages/tf_keras/src/engine/base_layer.py in __call__(self, *args, **kwargs)
1101 training=training_mode,
1102 ):
-> 1103 input_spec.assert_input_compatibility(
1104 self.input_spec, inputs, self.name
1105 )
/usr/local/lib/python3.10/dist-packages/tf_keras/src/engine/input_spec.py in assert_input_compatibility(input_spec, inputs, layer_name)
300 "incompatible with the layer: "
301 f"expected shape={spec.shape}, "
--> 302 f"found shape={display_shape(x.shape)}"
303 )
304
/usr/local/lib/python3.10/dist-packages/tf_keras/src/engine/input_spec.py in display_shape(shape)
305
306 def display_shape(shape):
--> 307 return str(tuple(shape.as_list()))
308
309
AttributeError: 'tuple' object has no attribute 'as_list'