deniswhite77

Untitled

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