Advertisement
Alaricy

Untitled

Sep 12th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. from keras.datasets import fashion_mnist
  2. from keras.layers import Dense
  3. from keras.models import Sequential
  4. from tensorflow.keras.optimizers import Adam
  5. import numpy as np
  6.  
  7. optimizer = Adam(lr=0.01)
  8.  
  9. def load_train(path):
  10.     features_train = np.load(path + 'train_features.npy')
  11.     target_train = np.load(path + 'train_target.npy')
  12.     features_train = features_train.reshape(features_train.shape[0], 28 * 28) / 255.
  13.     return features_train, target_train
  14.  
  15.  
  16. def create_model(input_shape): #Winer
  17.     model = Sequential()
  18.     model.add(Dense(100, activation="relu"))
  19.     model.add(Dense(10, activation="softmax"))
  20.     model.compile(optimizer=optimizer, loss='sparse_categorical_crossentropy',
  21.                   metrics=['acc'])
  22.  
  23.     return model
  24.  
  25.  
  26. def train_model(model, train_data, test_data, batch_size=32, epochs=10,
  27.                steps_per_epoch=None, validation_steps=None):
  28.  
  29.     features_train, target_train = train_data
  30.     features_test, target_test = test_data
  31.     model.fit(features_train, target_train,
  32.               validation_data=(features_test, target_test),
  33.               batch_size=batch_size, epochs=epochs,
  34.               steps_per_epoch=steps_per_epoch,
  35.               validation_steps=validation_steps,
  36.               verbose=2, shuffle=True)
  37.  
  38.     return model
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement