from tensorflow.keras.layers import Dropout from tensorflow.keras.layers import Flatten from tensorflow.keras.layers import GlobalAveragePooling2D from tensorflow.keras.layers import Input from tensorflow.keras.layers import LeakyReLU from tensorflow.keras.layers import MaxPool2D from tensorflow.keras.models import Model from tensorflow.keras.optimizers import Adam from mnistData import MNIST random.seed(0) np.random.seed(0) tf.random.set_seed(0) data = MNIST() data.data_augmentation(augment_size=10000) data.data_preprocessing(preprocess_mode="MinMax") ( x_train_splitted, x_val, y_train_splitted, y_val, ) = data.get_splitted_train_validation_set() x_train, y_train = data.get_train_set() x_test, y_test = data.get_test_set() num_classes = data.num_classes # Save Path dir_path = os.path.abspath( "C:/Users/Jan/Dropbox/_Programmieren/UdemyTF/models/")
x = Flatten()(x) x = Dense(units=num_classes)(x) y_pred = Activation("softmax")(x) model = Model( inputs=[input_img], outputs=[y_pred] ) model.summary() return model if __name__ == "__main__": data = MNIST(with_normalization=False) data.data_augmentation(augment_size=5_000) x_train_, x_val_, y_train_, y_val_ = data.get_splitted_train_validation_set() model = build_model(data.img_shape, data.num_classes) model.compile( loss="categorical_crossentropy", optimizer=Adam(learning_rate=0.0005), metrics=["accuracy"] ) tb_callback = TensorBoard( log_dir=MODEL_LOG_DIR, write_graph=True
x = Activation("relu")(x) x = MaxPool2D()(x) x = Flatten()(x) x = Dense(units=num_classes)(x) y_pred = Activation("softmax")(x) model = Model(inputs=[input_img], outputs=[y_pred]) model.summary() return model if __name__ == "__main__": data = MNIST(with_normalization=True) x_train_, x_val_, y_train_, y_val_ = data.get_splitted_train_validation_set( ) model = build_model(data.img_shape, data.num_classes) model.compile(loss="categorical_crossentropy", optimizer=Adam(learning_rate=0.0005), metrics=["accuracy"]) tb_callback = TensorBoard(log_dir=MODEL_LOG_DIR, write_graph=True) model.fit(x=x_train_, y=y_train_, epochs=40,
model = Model( inputs=[input_img], outputs=[y_pred] ) model.compile( loss="categorical_crossentropy", optimizer="Adam", metrics=["accuracy"] ) return model if __name__ == "__main__": data = MNIST(with_normalization=True) x_train, y_train = data.get_train_set() param_distributions = { "filters_1": randint(8, 64), "kernel_size_1": randint(3, 8), "filters_2": randint(8, 64), "kernel_size_2": randint(3, 8), "filters_3": randint(8, 64), "kernel_size_3": randint(3, 8), } keras_clf = KerasClassifier( build_fn=build_model, epochs=3,
x = Flatten()(x) x = Dense(units=128)(x) x = Activation("relu")(x) x = Dense(units=num_classes)(x) y_pred = Activation("softmax")(x) model = Model(inputs=[input_img], outputs=[y_pred]) model.summary() return model if __name__ == "__main__": data = MNIST() x_train, y_train = data.get_train_set() x_test, y_test = data.get_test_set() img_shape = data.img_shape num_classes = data.num_classes model = build_model(img_shape, num_classes) model.compile(loss="categorical_crossentropy", optimizer="Adam", metrics=["accuracy"]) model.fit(x=x_train / 255.0, y=y_train, epochs=3,