损失函数是categorical_crossentropy,
然后随便使用一张图片预测出来的结果总是:
预测概率要不就是100%,要不就是0%
[Python] 纯文本查看 复制代码
model=Sequential()
model.add(
Convolution2D(
32,5,padding="same",input_shape=(224,224,3),activation="relu"
)
)
model.add(
MaxPooling2D(
(2,2),padding="same"
)
)
model.add(
Convolution2D(
64,5,padding="same",activation="relu"
)
)
model.add(
MaxPooling2D(
(2,2),padding="same"
)
)
model.add(
Convolution2D(
128,5,padding="same",activation="relu"
)
)
model.add(
MaxPooling2D(
(2,2),padding="same"
)
)
model.add(Flatten())
model.add(
Dense(
128,activation="relu"
)
)
model.add(
Dense(
64,activation="relu"
)
)
model.add(
Dense(
10,activation="softmax"
)
)
model.compile(
Adam(lr=0.0001),loss="categorical_crossentropy",
metrics=["accuracy"]
)
img_generator=image.ImageDataGenerator(
rescale=1.0/255
)
train_img=img_generator.flow_from_directory(
"ANIMALS",
target_size=(224,224),
shuffle=True,
seed=54,
)
name=["bear","cat","cheetah","cow","crocodiles","deer","dogs","elephant","giraffe","goat"]
img_arr=image.load_img("1.jpg",target_size=(224,224));
img_arr=image.img_to_array(img_arr)
img_arr=np.expand_dims(img_arr,axis=0)
pre=model.predict(img_arr)
|