1. Design model
from keras.layers import Input, Dense, Activation, ZeroPadding2D, BatchNormalization, Flatten, Conv2D, MaxPooling2D, Dropout
from keras.models import Model
def Mymodel(input):
X_train = Input(input)
X = ZeroPadding2D((3, 3))(X_train)
X = Conv2D(32, (7, 7), strides = (1, 1))(X)
X = BatchNormalization(axis = 3)(X)
X = Activation('relu')(X)
X = MaxPooling2D((2, 2))(X)
X = Flatten()(X)
X = Dense(1, activation='sigmoid')(X) #fully connected layer
model = Model(inputs = X_input, outputs = X, name='Mymodel') # Create model.
return model
2. Create model
mymodel = Mymodel(X_train)
3. Compile model
mymodel.compile(optimizer = "adam", loss = "binary_crossentropy", metrics = ["accuracy"])
4. Train model
mymodel.fit(x = X_train, y = Y_train, epochs = 100, batch_size = 64)
5. Evaluate model
prediction = Mymodel.evaluate(x = X_test, y = Y_test)
print ("Loss = " + str(prediction[0]))
print ("Test Accuracy = " + str(prediction[1]))
'VISION' 카테고리의 다른 글
Coursera 딥러닝 과정 수강 - 배운 내용 정리 (0) | 2020.08.20 |
---|---|
PyTorch Basics (0) | 2020.08.02 |
ResNet with Keras (0) | 2020.08.01 |
TensorFlow Basics (0) | 2020.07.12 |
Gradient Descent Optimization - Mini batch, Momentum, RMS, Adam, Learning rate decay (0) | 2020.06.29 |