Spaces:
Running
Running
ignaziogallo
commited on
Commit
·
6cb40a3
1
Parent(s):
99ee6d2
resolved numpy bug
Browse files- .gitignore +2 -1
- app.py +2 -1
- 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(
|
| 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,
|
| 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
|
| 731 |
-
[0
|
| 732 |
-
[0
|
| 733 |
-
[0
|
| 734 |
-
[0
|
| 735 |
-
[
|
| 736 |
-
[0
|
| 737 |
-
[
|
| 738 |
-
[
|
| 739 |
-
[
|
| 740 |
-
[0
|
| 741 |
-
[
|
| 742 |
-
[
|
| 743 |
-
[0.
|
| 744 |
-
[
|
| 745 |
-
[139/255, 35/255, 35/255],
|
| 746 |
-
[
|
| 747 |
-
[0
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 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']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|