Spaces:
Runtime error
Runtime error
Niv Sardi
commited on
Commit
·
d48129a
1
Parent(s):
9477f68
python: fixups
Browse filesSigned-off-by: Niv Sardi <[email protected]>
- python/augment.py +3 -0
- python/entity.py +6 -2
- python/imtool.py +2 -3
python/augment.py
CHANGED
@@ -140,9 +140,12 @@ with pipeline.pool(processes=-1, seed=1) as pool:
|
|
140 |
label = logo_labels[orig.tobytes()]
|
141 |
logo = batch_aug.images_aug[logo_idx]
|
142 |
|
|
|
|
|
143 |
# XXX(xaiki): we get alpha from heatmap, but will only use one channel
|
144 |
# we could make mix_alpha into mix_mask and pass all 3 chanels
|
145 |
alpha = cv2.split(batch_aug.heatmaps_aug[logo_idx])
|
|
|
146 |
try:
|
147 |
bb = imtool.mix_alpha(img, logo, alpha[0],
|
148 |
random.random(), random.random())
|
|
|
140 |
label = logo_labels[orig.tobytes()]
|
141 |
logo = batch_aug.images_aug[logo_idx]
|
142 |
|
143 |
+
assert(logo.shape == orig.shape)
|
144 |
+
|
145 |
# XXX(xaiki): we get alpha from heatmap, but will only use one channel
|
146 |
# we could make mix_alpha into mix_mask and pass all 3 chanels
|
147 |
alpha = cv2.split(batch_aug.heatmaps_aug[logo_idx])
|
148 |
+
|
149 |
try:
|
150 |
bb = imtool.mix_alpha(img, logo, alpha[0],
|
151 |
random.random(), random.random())
|
python/entity.py
CHANGED
@@ -4,8 +4,12 @@ from typing import NamedTuple
|
|
4 |
|
5 |
from common import defaults
|
6 |
|
7 |
-
def
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
reader = csv.DictReader(csvfile)
|
10 |
bcos = { d['bco']:update(d, {'id': i}) for i, d in enumerate(reader)}
|
11 |
return bcos
|
|
|
4 |
|
5 |
from common import defaults
|
6 |
|
7 |
+
def update(d, i):
|
8 |
+
d.update(i)
|
9 |
+
return d
|
10 |
+
|
11 |
+
def read_entities(fn = defaults.MAIN_CSV_PATH):
|
12 |
+
with open(fn, newline='') as csvfile:
|
13 |
reader = csv.DictReader(csvfile)
|
14 |
bcos = { d['bco']:update(d, {'id': i}) for i, d in enumerate(reader)}
|
15 |
return bcos
|
python/imtool.py
CHANGED
@@ -21,7 +21,6 @@ class BoundingBox(NamedTuple):
|
|
21 |
@classmethod
|
22 |
def from_centroid(cls, c, shape):
|
23 |
(ih, iw, ic) = shape
|
24 |
-
print(cls, c, shape)
|
25 |
self = cls(x=math.floor(w*(c.x - c.w/2))
|
26 |
, y=math.floor(h*(c.y - c.h/2))
|
27 |
, w=math.ceil(w*c.w)
|
@@ -158,7 +157,7 @@ def mix_alpha(a, b, ba, fx, fy):
|
|
158 |
if (aw*p < bw or ah*p < bh):
|
159 |
f = min(p*aw/bw, p*ah/bh)
|
160 |
nw, nh = floor_point(bw*f, bh*f)
|
161 |
-
print(f'resizing
|
162 |
r = cv2.resize(b, (nw, nh), interpolation = cv2.INTER_LINEAR)
|
163 |
rba = cv2.resize(ba, (nw, nh), interpolation = cv2.INTER_LINEAR)
|
164 |
|
@@ -232,7 +231,7 @@ def crop(id, fn, logos: List[Centroid], out = './data/squares'):
|
|
232 |
li.append(p)
|
233 |
|
234 |
nim = cut_img(im, start, end)
|
235 |
-
rnim = cut_img(
|
236 |
img_name =f"{img_out}/{basename}-x{x}y{y}.jpg"
|
237 |
txt_name =f"{txt_out}/{basename}-x{x}y{y}.txt"
|
238 |
|
|
|
21 |
@classmethod
|
22 |
def from_centroid(cls, c, shape):
|
23 |
(ih, iw, ic) = shape
|
|
|
24 |
self = cls(x=math.floor(w*(c.x - c.w/2))
|
25 |
, y=math.floor(h*(c.y - c.h/2))
|
26 |
, w=math.ceil(w*c.w)
|
|
|
157 |
if (aw*p < bw or ah*p < bh):
|
158 |
f = min(p*aw/bw, p*ah/bh)
|
159 |
nw, nh = floor_point(bw*f, bh*f)
|
160 |
+
print(f'resizing to fit in {aw}x{ah}\t {bw}x{bh}\t=> {nw}x{nh}\tfactor {f}')
|
161 |
r = cv2.resize(b, (nw, nh), interpolation = cv2.INTER_LINEAR)
|
162 |
rba = cv2.resize(ba, (nw, nh), interpolation = cv2.INTER_LINEAR)
|
163 |
|
|
|
231 |
li.append(p)
|
232 |
|
233 |
nim = cut_img(im, start, end)
|
234 |
+
rnim = cut_img(rim, start, end)
|
235 |
img_name =f"{img_out}/{basename}-x{x}y{y}.jpg"
|
236 |
txt_name =f"{txt_out}/{basename}-x{x}y{y}.txt"
|
237 |
|