Commit 45c0a1e0 authored by Yuxin Wu's avatar Yuxin Wu

exception handling in zmq. clip_by_shape for floatbox

parent cb8b48d7
...@@ -198,7 +198,13 @@ class PrefetchDataZMQ(ProxyDataFlow): ...@@ -198,7 +198,13 @@ class PrefetchDataZMQ(ProxyDataFlow):
assert os.path.isdir(pipedir), pipedir assert os.path.isdir(pipedir), pipedir
self.pipename = "ipc://{}/dataflow-pipe-".format(pipedir.rstrip('/')) + str(uuid.uuid1())[:6] self.pipename = "ipc://{}/dataflow-pipe-".format(pipedir.rstrip('/')) + str(uuid.uuid1())[:6]
self.socket.set_hwm(self._hwm) self.socket.set_hwm(self._hwm)
self.socket.bind(self.pipename) try:
self.socket.bind(self.pipename)
except zmq.ZMQError:
logger.error(
"ZMQError in socket.bind(). Perhaps you're \
using pipes on a non-local file system. See documentation of PrefetchDataZMQ for more information.")
raise
self.procs = [PrefetchProcessZMQ(self.ds, self.pipename, self._hwm) self.procs = [PrefetchProcessZMQ(self.ds, self.pipename, self._hwm)
for _ in range(self.nr_proc)] for _ in range(self.nr_proc)]
......
...@@ -85,36 +85,11 @@ class IntBox(BoxBase): ...@@ -85,36 +85,11 @@ class IntBox(BoxBase):
assert self.is_valid_box(img.shape[:2]), "{} vs {}".format(self, img.shape[:2]) assert self.is_valid_box(img.shape[:2]), "{} vs {}".format(self, img.shape[:2])
return img[self.y1:self.y2 + 1, self.x1:self.x2 + 1] return img[self.y1:self.y2 + 1, self.x1:self.x2 + 1]
# def expand(self, frac):
# assert frac > 1.0, frac
# neww = self.w * frac
# newh = self.h * frac
# newx = self.x - (neww - self.w) * 0.5
# newy = self.y - (newh - self.h) * 0.5
# return Rect(*(map(int, [newx, newy, neww, newh])), allow_neg=True)
# def roi_zeropad(self, img):
# shp = list(img.shape)
# shp[0] = self.h
# shp[1] = self.w
# ret = np.zeros(tuple(shp), dtype=img.dtype)
# xstart = 0 if self.x >= 0 else -self.x
# ystart = 0 if self.y >= 0 else -self.y
# xmin = max(self.x0, 0)
# ymin = max(self.y0, 0)
# xmax = min(self.x1, img.shape[1])
# ymax = min(self.y1, img.shape[0])
# patch = img[ymin:ymax, xmin:xmax]
# ret[ystart:ystart + patch.shape[0], xstart:xstart + patch.shape[1]] = patch
# return ret
class FloatBox(BoxBase): class FloatBox(BoxBase):
def __init__(self, x1, y1, x2, y2): def __init__(self, x1, y1, x2, y2):
for k in [x1, y1, x2, y2]: for k in [x1, y1, x2, y2]:
assert isinstance(k, float) assert isinstance(k, float), "type={},value={}".format(type(k), k)
super(FloatBox, self).__init__(x1, y1, x2, y2) super(FloatBox, self).__init__(x1, y1, x2, y2)
@property @property
...@@ -130,9 +105,14 @@ class FloatBox(BoxBase): ...@@ -130,9 +105,14 @@ class FloatBox(BoxBase):
return FloatBox(intbox.x1, intbox.y1, return FloatBox(intbox.x1, intbox.y1,
intbox.x2 + 1, intbox.y2 + 1) intbox.x2 + 1, intbox.y2 + 1)
def clip_by_shape(self, shape):
self.x1 = np.clip(self.x1, 0, shape[1])
self.x2 = np.clip(self.x2, 0, shape[1])
self.y1 = np.clip(self.y1, 0, shape[0])
self.y2 = np.clip(self.y2, 0, shape[0])
if __name__ == '__main__': if __name__ == '__main__':
x = IntBox(2, 1, 3, 3) x = IntBox(2, 1, 3, 3)
img = np.random.rand(3, 3) img = np.random.rand(3, 3)
print(img) print(img)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment