mirror of
https://github.com/This-weiyuqing/ECG_by_Diffenert_CNN_Test.git
synced 2026-10-17 19:05:30 +08:00
may be last version
By completing the thesis, we have corrected the deficiencies and fixed some bugs.
This commit is contained in:
1 parent
a13e1ace47
commit
af187d92e9
49 files changed
+129
-7
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import numpy as np
|
||||
import keras
|
||||
from keras.models import Sequential
|
||||
from keras.layers import Dense, Dropout, Flatten
|
||||
from keras.layers import Conv2D, MaxPooling2D
|
||||
from keras.optimizers import SGD
|
||||
|
||||
# 生成虚拟数据
|
||||
x_train = np.random.random((100, 100, 100, 3))
|
||||
y_train = keras.utils.to_categorical(np.random.randint(10, size=(100, 1)), num_classes=10)
|
||||
x_test = np.random.random((20, 100, 100, 3))
|
||||
y_test = keras.utils.to_categorical(np.random.randint(10, size=(20, 1)), num_classes=10)
|
||||
|
||||
model = Sequential()
|
||||
# 输入: 3 通道 100x100 像素图像 -> (100, 100, 3) 张量。
|
||||
# 使用 32 个大小为 3x3 的卷积滤波器。
|
||||
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(100, 100, 3)))
|
||||
model.add(Conv2D(32, (3, 3), activation='relu'))
|
||||
model.add(MaxPooling2D(pool_size=(2, 2)))
|
||||
model.add(Dropout(0.25))
|
||||
|
||||
model.add(Conv2D(64, (3, 3), activation='relu'))
|
||||
model.add(Conv2D(64, (3, 3), activation='relu'))
|
||||
model.add(MaxPooling2D(pool_size=(2, 2)))
|
||||
model.add(Dropout(0.25))
|
||||
|
||||
model.add(Flatten())
|
||||
model.add(Dense(256, activation='relu'))
|
||||
model.add(Dropout(0.5))
|
||||
model.add(Dense(10, activation='softmax'))
|
||||
|
||||
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
|
||||
model.compile(loss='categorical_crossentropy', optimizer=sgd)
|
||||
|
||||
model.fit(x_train, y_train, batch_size=32, epochs=10)
|
||||
score = model.evaluate(x_test, y_test, batch_size=32)
|
||||
Reference in new issue
Block a user