Loading [MathJax]/jax/output/HTML-CSS/jax.js

Friday, October 9, 2020

Code Assignment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def HappyModel(input_shape):
    X_input = Input(input_shape)
     
    X = ZeroPadding2D((3,3))(X_input)
    X = Conv2D(18,(7,7),strides=(1,1),name="conv0")(X)
    X = BatchNormalization(axis=3, name="bn0")(X)
    X = Activation("relu")(X)
     
    X = MaxPooling2D((2,2), name="max_pool")(X)
     
    X = Flatten()(X)
    X = Dense(1,activation="sigmoid", name="fC")(X)
     
    model = Model(input = X_input, outputs = X, name="happy model")
     return model
 
happyModel = HappyModel(X_train.shape[1:])
      
happyModel.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"])
     
happyModel.fit(x=X_train, y=Y_train,epochs=10, batch_size=20)
     
preds = happyModel.evaluate(x=X_test,y=Y_test)
 
img_path = 'images/smile.jpg'
   
img = image.load_img(img_path, target_size=(64, 64))
imshow(img)
 
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
print(happyModel.predict(x))

No comments:

Post a Comment