vobecant
commited on
Commit
•
5a3c3dc
1
Parent(s):
2c42781
Initial commit.
Browse files- .idea/workspace.xml +24 -5
- examples/img1.jpg +0 -0
- requirements.txt +1 -2
- segmenter_model/utils.py +0 -49
.idea/workspace.xml
CHANGED
@@ -1,9 +1,7 @@
|
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<project version="4">
|
3 |
<component name="ChangeListManager">
|
4 |
-
<list default="true" id="5dd22f22-8223-4d55-99f9-57d1e00622d7" name="Default Changelist" comment="Initial commit."
|
5 |
-
<change beforePath="$PROJECT_DIR$/requirements.txt" beforeDir="false" afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" />
|
6 |
-
</list>
|
7 |
<option name="SHOW_DIALOG" value="false" />
|
8 |
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
9 |
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
@@ -50,7 +48,7 @@
|
|
50 |
<option name="number" value="Default" />
|
51 |
<option name="presentableId" value="Default" />
|
52 |
<updated>1647350746642</updated>
|
53 |
-
<workItem from="1647350750956" duration="
|
54 |
</task>
|
55 |
<task id="LOCAL-00001" summary="Initial commit.">
|
56 |
<created>1647352693910</created>
|
@@ -101,7 +99,28 @@
|
|
101 |
<option name="project" value="LOCAL" />
|
102 |
<updated>1647355534027</updated>
|
103 |
</task>
|
104 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
<servers />
|
106 |
</component>
|
107 |
<component name="TypeScriptGeneratedFilesManager">
|
|
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<project version="4">
|
3 |
<component name="ChangeListManager">
|
4 |
+
<list default="true" id="5dd22f22-8223-4d55-99f9-57d1e00622d7" name="Default Changelist" comment="Initial commit." />
|
|
|
|
|
5 |
<option name="SHOW_DIALOG" value="false" />
|
6 |
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
7 |
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
|
48 |
<option name="number" value="Default" />
|
49 |
<option name="presentableId" value="Default" />
|
50 |
<updated>1647350746642</updated>
|
51 |
+
<workItem from="1647350750956" duration="5088000" />
|
52 |
</task>
|
53 |
<task id="LOCAL-00001" summary="Initial commit.">
|
54 |
<created>1647352693910</created>
|
|
|
99 |
<option name="project" value="LOCAL" />
|
100 |
<updated>1647355534027</updated>
|
101 |
</task>
|
102 |
+
<task id="LOCAL-00008" summary="Initial commit.">
|
103 |
+
<created>1647355606191</created>
|
104 |
+
<option name="number" value="00008" />
|
105 |
+
<option name="presentableId" value="LOCAL-00008" />
|
106 |
+
<option name="project" value="LOCAL" />
|
107 |
+
<updated>1647355606191</updated>
|
108 |
+
</task>
|
109 |
+
<task id="LOCAL-00009" summary="Initial commit.">
|
110 |
+
<created>1647355689933</created>
|
111 |
+
<option name="number" value="00009" />
|
112 |
+
<option name="presentableId" value="LOCAL-00009" />
|
113 |
+
<option name="project" value="LOCAL" />
|
114 |
+
<updated>1647355689933</updated>
|
115 |
+
</task>
|
116 |
+
<task id="LOCAL-00010" summary="Initial commit.">
|
117 |
+
<created>1647355817619</created>
|
118 |
+
<option name="number" value="00010" />
|
119 |
+
<option name="presentableId" value="LOCAL-00010" />
|
120 |
+
<option name="project" value="LOCAL" />
|
121 |
+
<updated>1647355817619</updated>
|
122 |
+
</task>
|
123 |
+
<option name="localTasksCounter" value="11" />
|
124 |
<servers />
|
125 |
</component>
|
126 |
<component name="TypeScriptGeneratedFilesManager">
|
examples/img1.jpg
CHANGED
requirements.txt
CHANGED
@@ -3,5 +3,4 @@ torchvision
|
|
3 |
pillow
|
4 |
timm
|
5 |
pyyaml
|
6 |
-
einops
|
7 |
-
opencv-python
|
|
|
3 |
pillow
|
4 |
timm
|
5 |
pyyaml
|
6 |
+
einops
|
|
segmenter_model/utils.py
CHANGED
@@ -3,11 +3,9 @@ import math
|
|
3 |
# from segm.engine import seg2rgb
|
4 |
from collections import namedtuple
|
5 |
|
6 |
-
import cv2
|
7 |
import numpy as np
|
8 |
import torch.nn as nn
|
9 |
import torch.nn.functional as F
|
10 |
-
from PIL import Image
|
11 |
from timm.models.layers import trunc_normal_
|
12 |
|
13 |
import torch
|
@@ -333,18 +331,6 @@ def inference_picie(
|
|
333 |
seg_maps[i: i + WB] = probs
|
334 |
windows["seg_maps"] = seg_maps
|
335 |
|
336 |
-
if debug_file is not None:
|
337 |
-
if isinstance(im_rgb, torch.Tensor):
|
338 |
-
im_rgb = im_rgb.detach().cpu().numpy()
|
339 |
-
if len(im_rgb.shape) == 4:
|
340 |
-
im_rgb = im_rgb[0]
|
341 |
-
h, w = im.shape[-2:]
|
342 |
-
im_rgb = cv2.resize(im_rgb, (w, h), interpolation=cv2.INTER_LINEAR)
|
343 |
-
|
344 |
-
crops_rgb = np.stack(
|
345 |
-
sliding_window(im_rgb[None, :], flip, window_size, window_stride, channels_first=channel_first).pop(
|
346 |
-
"crop"))[:, 0]
|
347 |
-
|
348 |
im_seg_map = merge_windows(windows, window_size, ori_shape, no_softmax=decoder_features,
|
349 |
no_upsample=no_upsample, patch_size=None)
|
350 |
|
@@ -412,41 +398,6 @@ def inference(
|
|
412 |
# torch.cuda.empty_cache()
|
413 |
windows["seg_maps"] = seg_maps
|
414 |
|
415 |
-
if debug_file is not None:
|
416 |
-
if isinstance(im_rgb, torch.Tensor):
|
417 |
-
im_rgb = im_rgb.detach().cpu().numpy()
|
418 |
-
if len(im_rgb.shape) == 4:
|
419 |
-
im_rgb = im_rgb[0]
|
420 |
-
h, w = im.shape[-2:]
|
421 |
-
im_rgb = cv2.resize(im_rgb, (w, h), interpolation=cv2.INTER_LINEAR)
|
422 |
-
|
423 |
-
crops_rgb = np.stack(
|
424 |
-
sliding_window(im_rgb[None, :], flip, window_size, window_stride, channels_first=channel_first).pop(
|
425 |
-
"crop"))[:, 0]
|
426 |
-
|
427 |
-
windows_row = np.concatenate([w for w in crops_rgb], axis=1)
|
428 |
-
# print(windows_row)
|
429 |
-
try:
|
430 |
-
Image.fromarray(windows_row).save(debug_file)
|
431 |
-
except:
|
432 |
-
pass
|
433 |
-
|
434 |
-
suffix = debug_file[-4:]
|
435 |
-
debug_file = debug_file.replace(suffix, '_preds{}'.format(suffix))
|
436 |
-
windows_preds = seg_maps.argmax(dim=1).cpu().numpy()
|
437 |
-
windows_preds_row = np.concatenate([seg2rgb(wp, C, 255) for wp in windows_preds], axis=1)
|
438 |
-
windows_row_plus_preds = np.concatenate((windows_row, windows_preds_row), axis=0)
|
439 |
-
try:
|
440 |
-
Image.fromarray(windows_preds_row).save(debug_file)
|
441 |
-
except:
|
442 |
-
pass
|
443 |
-
|
444 |
-
debug_file = debug_file.replace(suffix, '_wImg{}'.format(suffix))
|
445 |
-
try:
|
446 |
-
Image.fromarray(windows_row_plus_preds).save(debug_file)
|
447 |
-
except:
|
448 |
-
pass
|
449 |
-
|
450 |
im_seg_map = merge_windows(windows, window_size, ori_shape, no_softmax=decoder_features,
|
451 |
no_upsample=no_upsample, patch_size=model.patch_size)
|
452 |
|
|
|
3 |
# from segm.engine import seg2rgb
|
4 |
from collections import namedtuple
|
5 |
|
|
|
6 |
import numpy as np
|
7 |
import torch.nn as nn
|
8 |
import torch.nn.functional as F
|
|
|
9 |
from timm.models.layers import trunc_normal_
|
10 |
|
11 |
import torch
|
|
|
331 |
seg_maps[i: i + WB] = probs
|
332 |
windows["seg_maps"] = seg_maps
|
333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
im_seg_map = merge_windows(windows, window_size, ori_shape, no_softmax=decoder_features,
|
335 |
no_upsample=no_upsample, patch_size=None)
|
336 |
|
|
|
398 |
# torch.cuda.empty_cache()
|
399 |
windows["seg_maps"] = seg_maps
|
400 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
401 |
im_seg_map = merge_windows(windows, window_size, ori_shape, no_softmax=decoder_features,
|
402 |
no_upsample=no_upsample, patch_size=model.patch_size)
|
403 |
|