ignaziogallo commited on
Commit
6cb40a3
·
1 Parent(s): 99ee6d2

resolved numpy bug

Browse files
Files changed (3) hide show
  1. .gitignore +2 -1
  2. app.py +2 -1
  3. utils.py +23 -35
.gitignore CHANGED
@@ -1,4 +1,5 @@
1
  venv
2
  __pycache__
3
  uploaded_samples
4
- demo_data/results
 
 
1
  venv
2
  __pycache__
3
  uploaded_samples
4
+ demo_data/results
5
+ .idea
app.py CHANGED
@@ -166,12 +166,13 @@ if st.paths is not None:
166
  target = np.squeeze(target)
167
  target = [classes_color_map[p] for p in target]
168
 
 
169
  fig, ax = plt.subplots()
170
  ax.imshow(target)
171
 
172
 
173
  markdown_legend = ''
174
- for c, l in zip(classes_color_map, labels_map):
175
  # print(colors.to_hex(c))
176
  markdown_legend += f'<div style="color:gray;background-color: {colors.to_hex(c)};">{l}</div><br>'
177
 
 
166
  target = np.squeeze(target)
167
  target = [classes_color_map[p] for p in target]
168
 
169
+
170
  fig, ax = plt.subplots()
171
  ax.imshow(target)
172
 
173
 
174
  markdown_legend = ''
175
+ for c, l in zip(color_labels, labels_map):
176
  # print(colors.to_hex(c))
177
  markdown_legend += f'<div style="color:gray;background-color: {colors.to_hex(c)};">{l}</div><br>'
178
 
utils.py CHANGED
@@ -658,7 +658,7 @@ class FPN(nn.Module):
658
 
659
 
660
  def ids_to_labels(dataloader, pred_labels):
661
- new = np.zeros(pred_labels.shape, np.int)
662
  for cl, i in zip(dataloader.dataset.classids, range(len(dataloader.dataset.classids))):
663
  if type(cl) is list:
664
  new[pred_labels == i] = cl[0]
@@ -727,37 +727,25 @@ os.environ['CUDA_VISIBLE_DEVICES'] = opt.gpu_id
727
  if opt.no_cuda:
728
  os.environ['CUDA_VISIBLE_DEVICES'] = ""
729
 
730
- classes_color_map = np.array([[0., 0., 0.], # Black
731
- [0.79215686, 1.00000000, 0.43921569], # DarkGreen
732
- [0.78039216, 0.08235294, 0.52156863], # MediumVioletRed
733
- [0.00000000, 0.39215686, 0.00000000], # DarkOliveGreen1
734
- [0, 0, 1], # Blue
735
- [1.00000000, 0.84313725, 0.00000000], # gold
736
- [0.62745098, 0.12549020, 0.94117647], # purple
737
- [0.0, 100/255, 0.0], # DarkGreen
738
- [0.98039216, 0.66666667, 0.62745098], #
739
- [1, 1, 0], # yellow
740
- [0.2745098, 0.2745098, 0.2745098], #
741
- [0, 250/255, 154/255], # MediumSpringGreen
742
- [64/255, 224/255, 208/255], # turquoise
743
- [0.70588235, 0.64705882, 0.70588235], #
744
- [0.58823529, 0.39215686, 0.39215686], #
745
- [139/255, 35/255, 35/255], # brown4
746
- [0.6, 0.6, 0.6],
747
- [0.98039216, 0.66666667, 0.11764706],
748
- [0.8627451, 0.8627451, 0.],
749
- [0.41960784, 0.55686275, 0.1372549],
750
- [0.2745098, 0.50980392, 0.70588235],
751
- [0.8627451, 0.07843137, 0.23529412],
752
- [1., 0., 0.],
753
- [0., 0., 0.55686275],
754
- [0., 0., 0.2745098],
755
- [0., 0.23529412, 0.39215686],
756
- [0., 0., 0.35294118],
757
- [0., 0., 0.43137255],
758
- [0., 0.31372549, 0.39215686],
759
- [0., 0., 0.90196078],
760
- [0.46666667, 0.04313725, 0.1254902],
761
- [0., 0., 0.55686275]])
762
- colors = classes_color_map[:8] # num classes
763
- labels_map = ['Unknown', 'Other cereals', 'Woods and other tree crops', 'Forage', 'Corn', 'Rice', 'Unknow cropland', 'No arable land']
 
658
 
659
 
660
  def ids_to_labels(dataloader, pred_labels):
661
+ new = np.zeros(pred_labels.shape, int)
662
  for cl, i in zip(dataloader.dataset.classids, range(len(dataloader.dataset.classids))):
663
  if type(cl) is list:
664
  new[pred_labels == i] = cl[0]
 
727
  if opt.no_cuda:
728
  os.environ['CUDA_VISIBLE_DEVICES'] = ""
729
 
730
+ classes_color_map = np.array([[255/255.0, 255/255.0, 255/255.0],
731
+ [150/255.0, 150/255.0, 150/255.0], # Gray - 1 - Unknow cropland
732
+ [255/255.0, 0, 0], # Red - 2 - Other cereals
733
+ [161/255.0, 0, 0],
734
+ [0., 255/255.0, 0], # Green - 4 - Woods and other tree crops
735
+ [255/255.0, 240/255.0, 0],
736
+ [130/255.0, 120/255.0, 240/255.0],
737
+ [255/255.0, 136/255.0, 0], # Orange - 7 - Forage
738
+ [250, 190, 190],
739
+ [255/255.0, 255/255.0, 0], # Yellow - 9 - Corn
740
+ [0, 250, 154],
741
+ [64, 224, 208],
742
+ [0/255.0, 255/255.0, 255/255.0], # Turchese - 12 - Rice
743
+ [0.58823529, 0.39215686, 0.39215686],
744
+ [139/255, 35/255, 35/255],
745
+ [139/255, 35/255, 35/255],
746
+ [139/255, 35/255, 35/255],
747
+ [0, 0, 0], # Black - 17 - No Arable land
748
+ ])
749
+ color_labels = [classes_color_map[1], classes_color_map[2], classes_color_map[4], classes_color_map[7],
750
+ classes_color_map[9], classes_color_map[12], classes_color_map[17]]
751
+ labels_map = ['Unknow cropland', 'Other cereals', 'Woods and other tree crops', 'Forage', 'Corn', 'Rice', 'No arable land']