我用 MLP 尝试了下面的代码,现在我需要用具有以下结构的 CNN 8 层替换这个 MLP 代码:3×3×32 Convolutional → 3×3×64 Convolutional → 2×2 MaxPool → Dropout → Flatten → 1 × 128全连接→Dropout→128×10 全连接→Softmax。
//declear path to your mnist data folder
img_path = 'c:/kaggleMNISTdata/trainingSet/trainingSet'
//get the path list using the path object
image_paths = list(paths.list_images(img_path))
//apply our function
image_list, label_list = load(image_paths, verbose=10000)
// binarize the labels
lb = LabelBinarizer()
label_list = lb.fit_transform(label_list)
// split data into training and test set
X_train, X_test, y_train, y_test = train_test_split(image_list,
label_list,
test_size=0.1,
random_state=42)
data = list(zip(image_list, label_list))
random.shuffle(data)
class SimpleMLP:
@staticmethod
def build(shape, classes):
model = Sequential()
model.add(Dense(200, input_shape=(shape,)))
model.add(Activation("relu"))
model.add(Dense(200))
model.add(Activation("relu"))
model.add(Dense(classes))
model.add(Activation("softmax"))
return model
我试过以下
def build(shape, classes):
model = Sequential()
model.add(Conv2D(200, input_shape=(shape,)))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten(1))
model.add(Dropout(1))
model.add(Dense(200))
model.add(Activation("softmax"))
return model
这是对的吗?