taltaf9133 commited on
Commit
08f8658
·
1 Parent(s): 649bf2d

remove model monitoring

Browse files
Files changed (1) hide show
  1. app.py +1 -70
app.py CHANGED
@@ -31,76 +31,7 @@ N_IMAGES = 100
31
  # Define the model and its parameters
32
  #model = joblib.load(filename="plant_leaf_diseases_model.keras", 'utf-8')
33
  model = tf.keras.models.load_model('plant_leaf_diseases_model.keras')
34
- #test_dir_img_file_path = os.path.getcwd("imagesfolder")
35
- test_dir_img_file_path = os.path.join(os.getcwd(),"imagesfolder")
36
- # Define the metrics
37
- accuracy = prom.Gauge("accuracy", "precision score for random 50 test samples")
38
- precision_metric = prom.Gauge("plant_precision", "precision score for random 50 test samples")
39
- recall_metric = prom.Gauge("plant_recall_score", "recall score for random 50 test samples")
40
- f1_metric = prom.Gauge("plant_f1_score", "F1 score for random 50 test samples")
41
-
42
- # Define the function to make predictions
43
- #def make_prediction(test_dir_img_file_path):
44
- # # Load the test images
45
- # image_list = []
46
- # for plant_image in os.listdir(test_dir_img_file_path):
47
- ## if plant_image.endswith(".jpg") or plant_image.endswith(".JPG"):
48
- # image_list.append(convert_image_to_array(os.path.join(test_dir_img_file_path, plant_image)))
49
- # np_image_list = np.array(image_list, dtype=np.float16) / config.model_config.scaling_factor
50
- #
51
- # # Make predictions
52
- # predictions = model.predict(np_image_list, verbose=0)
53
-
54
- # Return the predictions
55
- # return {"predictions": predictions, "version": _version}
56
- def convert_image_to_array(image_dir):
57
- try:
58
- print(image_dir)
59
- image = cv2.imread(image_dir)
60
- if image is not None:
61
- image = cv2.resize(image, DEFAULT_IMAGE_SIZE)
62
- return img_to_array(image)
63
- else :
64
- return np.array([])
65
- except Exception as e:
66
- print(f"Error : {e}")
67
- return None
68
- # Define the function to update the metrics
69
- x_test, y_test = train_test_split(test_dir_img_file_path)
70
- def update_metrics():
71
- # Load the test images
72
- image_list = []
73
- plant_disease_folder_list = listdir(test_dir_img_file_path)
74
- for plant_disease_folder in plant_disease_folder_list:
75
- plant_disease_image_list = listdir(f"{test_dir_img_file_path}/{plant_disease_folder}/")
76
- for plant_image in plant_disease_image_list[:N_IMAGES]:
77
- plant_image_directory = f"{test_dir_img_file_path}/{plant_disease_folder}/{image}"
78
- if plant_image_directory.endswith(".jpg") or plant_image_directory.endswith(".JPG"):
79
- image_list.append(convert_image_to_array(os.path.join(plant_image_directory)))
80
- label_list.append(plant_disease_folder)
81
- image_len = len(image_list)
82
- print(f"Total number of images: {image_len}")
83
- np_image_list = np.array(image_list, dtype=np.float16) / 255.0
84
- # Make predictions
85
- predictions = model.predict(np_image_list, verbose=0)
86
-
87
- # Calculate the metrics
88
- pred = np.argmax(predictions, axis=1)
89
- y_test2 = np.argmax(y_test, axis=1)
90
- accuracy = accuracy_score(y_true, y_pred)
91
- precision = precision_score(y_test2, pred)
92
- recall = recall_score(y_test2, predictions)
93
- f1 = f1_score(y_test2, predictions)
94
-
95
- # Update the metrics
96
- precision_metric.set(precision)
97
- recall_metric.set(recall)
98
- f1_metric.set(f1)
99
-
100
- @app.get("/metrics")
101
- async def get_metrics():
102
- update_metrics()
103
- return Response(media_type="text/plain", content= prom.generate_latest())
104
 
105
 
106
  myControls = {
 
31
  # Define the model and its parameters
32
  #model = joblib.load(filename="plant_leaf_diseases_model.keras", 'utf-8')
33
  model = tf.keras.models.load_model('plant_leaf_diseases_model.keras')
34
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
 
37
  myControls = {