Semi-automated CNN generation procedure

Create Auto_cteate_code,it can create CNN by Semi-automated
This commit is contained in:
weiyuqing committed 2023-03-28 15:33:27 +08:00
1 parent a2df8fb8d1
commit a65c5ceef9
3 files changed
+141

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
import datetime
import os
import numpy as np
import tensorflow as tf
from utils_seventyOne_of_Filters import loadData, plot_history_tf, plot_heat_mapProject_PATH = "../some-test\def main():
X_train, X_test, y_train, y_test = loadData(RATIO, RANDOM_SEED)
if os.path.exists(model_Path_one):
print(' get model in h5 file')
model = tf.keras.models.load_model(filepath=model_Path_one)
else:
# create new model(if model unexists)
model = CNN_model_level_one()
model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])
model.summary()
# TB make
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir,
histogram_freq=1,
)
# Training and validation
history = model.fit(X_train, y_train, epochs=NUM_EPOCHS,
batch_size=BATCH_SIZE,
validation_data=(X_test, y_test),
callbacks=[tensorboard_callback])
# validation_split=RATIO,
model.save(filepath=model_Path_one)
plot_history_tf(history)
y_pred = np.argmax(model.predict(X_test), axis=-1)
plot_heat_map(y_test, y_pred)