BunkerMinecraft commited on
Commit
8d49dab
·
verified ·
1 Parent(s): 1eacefd

Update inference.py

Browse files
Files changed (1) hide show
  1. inference.py +9 -9
inference.py CHANGED
@@ -14,12 +14,12 @@ base_model = tf.keras.applications.EfficientNetB7(weights=None)
14
  model = models.Sequential([
15
  base_model,
16
  layers.GlobalAveragePooling2D(),
17
- layers.Dropout(dropout_rate),
18
- layers.Dense(256, activation='relu', kernel_regularizer=kr),
19
- layers.Dropout(dropout_rate),
20
- layers.Dense(128, activation='relu', kernel_regularizer=kr),
21
- layers.Dropout(dropout_rate),
22
- layers.Dense(num_classes, activation='softmax')
23
  ])
24
  model.load_weights("model.weights.h5")
25
 
@@ -31,9 +31,9 @@ def preprocess(image: Image.Image):
31
 
32
  def predict(image: Image.Image):
33
  x = preprocess(image)
34
- y = model.predict(x)
35
- class_idx = int(np.argmax(y, axis=1)[0])
36
- confidence = float(np.max(y))
37
  return {
38
  "class": class_names[class_idx],
39
  "confidence": confidence
 
14
  model = models.Sequential([
15
  base_model,
16
  layers.GlobalAveragePooling2D(),
17
+ layers.Dropout(0.3),
18
+ layers.Dense(256, activation='relu', kernel_regularizer=regularizers.l2(0.001)),
19
+ layers.Dropout(0.3),
20
+ layers.Dense(128, activation='relu', kernel_regularizer=regularizers.l2(0.001)),
21
+ layers.Dropout(0.3),
22
+ layers.Dense(6, activation='softmax')
23
  ])
24
  model.load_weights("model.weights.h5")
25
 
 
31
 
32
  def predict(image: Image.Image):
33
  x = preprocess(image)
34
+ x = model.predict(x)
35
+ class_idx = int(np.argmax(x, axis=1)[0])
36
+ confidence = float(np.max(x))
37
  return {
38
  "class": class_names[class_idx],
39
  "confidence": confidence