Alexvatti commited on
Commit
662786f
·
verified ·
1 Parent(s): 469f05c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -63,6 +63,29 @@ def cce_dice_loss(y_true, y_pred):
63
  dice = dice_loss(y_true, y_pred)
64
  return tf.cast(cce, dtype=tf.float32) + dice
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  def readImages(data, typeData, width, height):
67
  images = []
68
  for img in data:
@@ -84,7 +107,7 @@ def readImages(data, typeData, width, height):
84
  img = cv2.imread(str(img), cv2.IMREAD_COLOR)
85
  img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
86
  img = cv2.resize(img, (width, height), interpolation=cv2.INTER_NEAREST)
87
- images.append(self.convertColorToLabel(img))
88
 
89
  elif typeData == 'o': # Optic image
90
  img = cv2.imread(str(img), cv2.IMREAD_COLOR)
 
63
  dice = dice_loss(y_true, y_pred)
64
  return tf.cast(cce, dtype=tf.float32) + dice
65
 
66
+ def convertColorToLabel(img):
67
+ color_to_label = {
68
+ (115, 178, 115): 0, # non_mining_land (green)
69
+ (255, 0, 0): 1, # illegal_mining_land (red)
70
+ (0, 0, 0): 2, # beach (black)
71
+ }
72
+
73
+ # Create empty label array
74
+ label_img = np.zeros((img.shape[0], img.shape[1]), dtype=np.uint8)
75
+
76
+ # Map each RGB color to its corresponding label
77
+ for color, label in color_to_label.items():
78
+ mask = np.all(img == color, axis=2)
79
+ label_img[mask] = label
80
+
81
+ # One-hot encode the label image
82
+ num_classes = len(color_to_label)
83
+ one_hot = np.zeros((img.shape[0], img.shape[1], num_classes), dtype=np.uint8)
84
+ for c in range(num_classes):
85
+ one_hot[:, :, c] = (label_img == c).astype(np.uint8)
86
+
87
+ return one_hot
88
+
89
  def readImages(data, typeData, width, height):
90
  images = []
91
  for img in data:
 
107
  img = cv2.imread(str(img), cv2.IMREAD_COLOR)
108
  img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
109
  img = cv2.resize(img, (width, height), interpolation=cv2.INTER_NEAREST)
110
+ images.append(convertColorToLabel(img))
111
 
112
  elif typeData == 'o': # Optic image
113
  img = cv2.imread(str(img), cv2.IMREAD_COLOR)