Передача обучения с использованием Keras для классификации изображенийPython

Программы на Python
Anonymous
Передача обучения с использованием Keras для классификации изображений

Сообщение Anonymous »

Я пытаюсь использовать уже обученную модель, чтобы перенести обучение в модель, которую я создам, и изменяю только несколько последних слоев. Целью этого является использование уже обученной модели (уже обученной на миллионах изображений), чтобы помочь моей модели классифицировать распознавание продуктов питания. Я новичок в Keras и столкнулся с проблемой, которую сейчас начинаю понимать, но не знаю, как решить
# Load the model from TensorFlow Hub
model_url = "https://www.kaggle.com/models/tensorflo ... fication/1"
hub_layer = hub.KerasLayer(model_url, input_shape=(224, 224, 3))

# Create a Sequential model
model = tf.keras.Sequential()

# Add the TensorFlow Hub layer to the Sequential model
model.add(hub_layer)

# Build the Sequential model
model.build((None, 224, 224, 3))

# Summary of the model
model.summary()

ОШИБКА:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[56], line 9
6 model = tf.keras.Sequential()
8 # Add the TensorFlow Hub layer to the Sequential model
----> 9 model.add(hub_layer)
11 # Build the Sequential model
12 model.build((None, 224, 224, 3))

File c:\Users\Karim\AppData\Local\Programs\Python\Python312\Lib\site-packages\keras\src\models\sequential.py:95, in Sequential.add(self, layer, rebuild)
93 layer = origin_layer
94 if not isinstance(layer, Layer):
---> 95 raise ValueError(
96 "Only instances of `keras.Layer` can be "
97 f"added to a Sequential model. Received: {layer} "
98 f"(of type {type(layer)})"
99 )
100 if not self._is_layer_name_unique(layer):
101 raise ValueError(
102 "All layers added to a Sequential model "
103 f"should have unique names. Name '{layer.name}' is already "
104 "the name of a layer in this model. Update the `name` argument "
105 "to pass a unique name."
106 )

ValueError: Only instances of `keras.Layer` can be added to a Sequential model. Received: (of type )


Подробнее здесь: https://stackoverflow.com/questions/784 ... sification

Вернуться в «Python»