为方便试验,在纸上花了指针进行旋转,表示移动
使用CNN进行训练 epochs:50, batch size:16, Learn rate:0.001

# 构建CNN模型
model = Sequential()
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(240, 240, 3)))
model.add(MaxPooling2D((2, 2)))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D((2, 2)))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dense(num_classes, activation='softmax')) 

生成训练数据

        train_gen = ImageDataGenerator(rescale=1./255, rotation_range=10, horizontal_flip=True, shear_range=0.2, fill_mode='nearest')
        train_gen = train_gen.flow_from_directory(train_data_dir, target_size=(240, 240), batch_size=16, class_mode='categorical')

训练和评估


        model.fit(train_gen, epochs=50, validation_data=test_gen)

预测

        y_pred = model.predict(test_gen)
        pred_classes = np.argmax(y_pred, axis=1)

以下是用openCV进行读取

By liu

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注