hamdan07 commited on
Commit
18c9491
1 Parent(s): 2a854f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -22
app.py CHANGED
@@ -38,35 +38,35 @@ def classify_image(inp):
38
  class_mode='sparse')
39
 
40
 
41
- def design_model():
42
- model = Sequential()
43
- model.add(tf.keras.Input(shape=(256, 256, 1)))
44
 
45
- model.add(tf.keras.layers.Conv2D(2, 5, strides=3, activation="relu"))
46
- model.add(tf.keras.layers.MaxPooling2D(pool_size=(5, 5), strides=(5,5)))
47
- model.add(tf.keras.layers.Conv2D(4, 3, strides=1, activation="relu"))
48
- model.add(tf.keras.layers.MaxPooling2D(pool_size=(3,2), strides=(2,2)))
49
 
50
- model.add(tf.keras.layers.Flatten())
51
  #model.add(tf.keras.layers.Dense(8, activation="relu"))
52
  #model.add(tf.keras.layers.Dropout(.20))
53
- model.add(tf.keras.layers.Dense(4, activation='softmax'))
54
 
55
- model.summary()
56
 
57
- callback = tf.keras.callbacks.EarlyStopping(monitor='accuracy', patience=5, restore_best_weights=True, verbose=1)
58
 
59
- print("Model designed")
60
- return model, callback
61
 
62
 
63
- model, es_callback = design_model()
64
 
65
- model.compile(loss='sparse_categorical_crossentropy',
66
  optimizer=keras.optimizers.Adam(learning_rate=0.01),
67
  metrics=['accuracy'])
68
 
69
- history = model.fit_generator(train_iterator,
70
  epochs=50,
71
  steps_per_epoch=50,
72
  validation_data=test_iterator,
@@ -74,12 +74,12 @@ history = model.fit_generator(train_iterator,
74
  callbacks=[es_callback],
75
  verbose=1)
76
 
77
- plt.plot(history.history['accuracy'])
78
- plt.title('model accuracy')
79
- plt.ylabel('accuracy')
80
- plt.xlabel('epoch')
81
- plt.legend(['train'], loc='upper left')
82
- plt.show()
83
 
84
  title = "Gradio Image Classifiction + Interpretation Example"
85
  gr.Interface(
 
38
  class_mode='sparse')
39
 
40
 
41
+ def design_model():
42
+ model = Sequential()
43
+ model.add(tf.keras.Input(shape=(256, 256, 1)))
44
 
45
+ model.add(tf.keras.layers.Conv2D(2, 5, strides=3, activation="relu"))
46
+ model.add(tf.keras.layers.MaxPooling2D(pool_size=(5, 5), strides=(5,5)))
47
+ model.add(tf.keras.layers.Conv2D(4, 3, strides=1, activation="relu"))
48
+ model.add(tf.keras.layers.MaxPooling2D(pool_size=(3,2), strides=(2,2)))
49
 
50
+ model.add(tf.keras.layers.Flatten())
51
  #model.add(tf.keras.layers.Dense(8, activation="relu"))
52
  #model.add(tf.keras.layers.Dropout(.20))
53
+ model.add(tf.keras.layers.Dense(4, activation='softmax'))
54
 
55
+ model.summary()
56
 
57
+ callback = tf.keras.callbacks.EarlyStopping(monitor='accuracy', patience=5, restore_best_weights=True, verbose=1)
58
 
59
+ print("Model designed")
60
+ return model, callback
61
 
62
 
63
+ model, es_callback = design_model()
64
 
65
+ model.compile(loss='sparse_categorical_crossentropy',
66
  optimizer=keras.optimizers.Adam(learning_rate=0.01),
67
  metrics=['accuracy'])
68
 
69
+ history = model.fit_generator(train_iterator,
70
  epochs=50,
71
  steps_per_epoch=50,
72
  validation_data=test_iterator,
 
74
  callbacks=[es_callback],
75
  verbose=1)
76
 
77
+ plt.plot(history.history['accuracy'])
78
+ plt.title('model accuracy')
79
+ plt.ylabel('accuracy')
80
+ plt.xlabel('epoch')
81
+ plt.legend(['train'], loc='upper left')
82
+ plt.show()
83
 
84
  title = "Gradio Image Classifiction + Interpretation Example"
85
  gr.Interface(