Gaetano Parente commited on
Commit
d8a4180
·
1 Parent(s): c3cd511

rimosso utilizzo image temporanea

Browse files
modules/__pycache__/__init__.cpython-311.pyc CHANGED
Binary files a/modules/__pycache__/__init__.cpython-311.pyc and b/modules/__pycache__/__init__.cpython-311.pyc differ
 
modules/__pycache__/binary_classification.cpython-311.pyc CHANGED
Binary files a/modules/__pycache__/binary_classification.cpython-311.pyc and b/modules/__pycache__/binary_classification.cpython-311.pyc differ
 
modules/__pycache__/image_classification.cpython-311.pyc CHANGED
Binary files a/modules/__pycache__/image_classification.cpython-311.pyc and b/modules/__pycache__/image_classification.cpython-311.pyc differ
 
modules/__pycache__/multilabel_classification.cpython-311.pyc CHANGED
Binary files a/modules/__pycache__/multilabel_classification.cpython-311.pyc and b/modules/__pycache__/multilabel_classification.cpython-311.pyc differ
 
modules/image_classification.py CHANGED
@@ -4,35 +4,26 @@ import keras.models as models
4
  from flask import jsonify
5
  import os
6
  from modules.utilities.utils import allowed_model
7
- import uuid
8
 
9
  IMAGE_SIZE = (224, 224)
10
  class_names = ['Tubercolosi', 'No_Tubercolosi', 'Pneumonia', 'No_Pneumonia']
11
  BASE_PATH = './data/'
12
  MODEL = BASE_PATH + 'model/'
13
 
14
- def image_predict(image_path, model_path):
15
- image = cv2.imread(image_path)
16
- # image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
17
- image = cv2.resize(image, IMAGE_SIZE)
18
  images = []
19
  images.append(image)
20
  images = np.array(images, dtype='float32')
21
  model = models.load_model(model_path, compile=False)
22
  predictions = model.predict(images) # Vector of probabilities
23
- pred_labels = np.argmax(predictions, axis= 1)
24
- return predictions, pred_labels
25
 
26
  def image_classification(numpy_image):
27
  model = MODEL + 'medical-image-classification.h5'
28
- myuuid = uuid.uuid4()
29
- filename = 'test_' + str(myuuid) + '.png'
30
- cv2.imwrite(filename, numpy_image)
31
- try:
32
- labels, max_label = image_predict(filename, model)
33
- response = {}
34
- for i, label in enumerate(labels[0]):
35
- response[class_names[i]] = "%.4f" % float(label)
36
- return response
37
- finally:
38
- os.remove(filename)
 
4
  from flask import jsonify
5
  import os
6
  from modules.utilities.utils import allowed_model
 
7
 
8
  IMAGE_SIZE = (224, 224)
9
  class_names = ['Tubercolosi', 'No_Tubercolosi', 'Pneumonia', 'No_Pneumonia']
10
  BASE_PATH = './data/'
11
  MODEL = BASE_PATH + 'model/'
12
 
13
+ def image_predict(numpy_image, model_path):
14
+ image = cv2.resize(numpy_image, IMAGE_SIZE)
 
 
15
  images = []
16
  images.append(image)
17
  images = np.array(images, dtype='float32')
18
  model = models.load_model(model_path, compile=False)
19
  predictions = model.predict(images) # Vector of probabilities
20
+ #pred_labels = np.argmax(predictions, axis= 1)
21
+ return predictions#, pred_labels
22
 
23
  def image_classification(numpy_image):
24
  model = MODEL + 'medical-image-classification.h5'
25
+ labels = image_predict(numpy_image, model)
26
+ response = {}
27
+ for i, label in enumerate(labels[0]):
28
+ response[class_names[i]] = "%.4f" % float(label)
29
+ return response
 
 
 
 
 
 
modules/utilities/__pycache__/__init__.cpython-311.pyc CHANGED
Binary files a/modules/utilities/__pycache__/__init__.cpython-311.pyc and b/modules/utilities/__pycache__/__init__.cpython-311.pyc differ
 
modules/utilities/__pycache__/utils.cpython-311.pyc CHANGED
Binary files a/modules/utilities/__pycache__/utils.cpython-311.pyc and b/modules/utilities/__pycache__/utils.cpython-311.pyc differ