下面是我的代码:
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
x_train, y_train), (x_test, y_test) = keras.datasets.cifar100.load_data()
num_of_class = 100
y_train = keras.utils.to_categorical(y_train, num_of_class)
y_test = keras.utils.to_categorical(y_test, num_of_class)
x_train = x_train.astype(float) / 255.0
x_test = x_test.astype(float) / 255.0
model_2 = keras.Sequential()
model_2.add(keras.layers.Input(shape=x_train[0].shape))
model_2.add(keras.layers.Conv2D(filters=256, kernel_size=(3,3), activation='ReLU'))
model_2.add(keras.layers.Conv2D(filters=256, kernel_size=(3,3), activation='ReLU'))
model_2.add(keras.layers.Conv2D(filters=256, kernel_size=(3,3), activation='ReLU'))
model_2.add(keras.layers.Conv2D(filters=256, kernel_size=(3,3), activation='ReLU'))
model_2.add(keras.layers.Conv2D(filters=256, kernel_size=(3,3), strides=(2,2), activation='ReLU'))
model_2.add(keras.layers.MaxPooling2D(pool_size=(2, 2)))
model_2.add(keras.layers.Flatten(input_shape=x_train[0].shape))
model_2.add(keras.layers.Dense(units=num_of_class, activation='softmax'))
model_2.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
history_2 = model_1.fit(x_train, y_train, batch_size=512, epochs=50, validation_data=(x_test, y_test), shuffle=True)`
字符串
实际上,我对机器学习和计算机视觉是个新手。我只是想尝试这个代码分类cifar 100图片,但发生的事情是令人失望的。在所有50个纪元中我都有这个
损耗:0.0100 -准确度:0.0100 -瓦尔_loss:0.0100 -瓦尔_accuracy:0.0100
1条答案
按热度按时间jexiocij1#
Model_1未定义。如果要训练模型,则将其定义为model_2
第一个月
还有一些语法错误