Commit 8f917c01 authored by Yuxin Wu's avatar Yuxin Wu

remove pipedir from zmq. fix resnet rgb/bgr (fix #176)

parent 2d5984db
...@@ -31,6 +31,8 @@ class Model(ModelDesc): ...@@ -31,6 +31,8 @@ class Model(ModelDesc):
image, label = inputs image, label = inputs
image = tf.cast(image, tf.float32) * (1.0 / 255) image = tf.cast(image, tf.float32) * (1.0 / 255)
# Wrong mean/std are used for compatibility with pre-trained models.
# Should actually add a RGB-BGR conversion here.
image_mean = tf.constant([0.485, 0.456, 0.406], dtype=tf.float32) image_mean = tf.constant([0.485, 0.456, 0.406], dtype=tf.float32)
image_std = tf.constant([0.229, 0.224, 0.225], dtype=tf.float32) image_std = tf.constant([0.229, 0.224, 0.225], dtype=tf.float32)
image = (image - image_mean) / image_std image = (image - image_mean) / image_std
...@@ -159,11 +161,14 @@ def get_data(train_or_test): ...@@ -159,11 +161,14 @@ def get_data(train_or_test):
[imgaug.Brightness(30, clip=False), [imgaug.Brightness(30, clip=False),
imgaug.Contrast((0.8, 1.2), clip=False), imgaug.Contrast((0.8, 1.2), clip=False),
imgaug.Saturation(0.4), imgaug.Saturation(0.4),
# rgb-bgr conversion
imgaug.Lighting(0.1, imgaug.Lighting(0.1,
eigval=[0.2175, 0.0188, 0.0045], eigval=[0.2175, 0.0188, 0.0045][::-1],
eigvec=[[-0.5675, 0.7192, 0.4009], eigvec=np.array(
[-0.5808, -0.0045, -0.8140], [[-0.5675, 0.7192, 0.4009],
[-0.5836, -0.6948, 0.4203]] [-0.5808, -0.0045, -0.8140],
[-0.5836, -0.6948, 0.4203]],
dtype='float32')[::-1, ::-1]
)]), )]),
imgaug.Clip(), imgaug.Clip(),
imgaug.Flip(horiz=True), imgaug.Flip(horiz=True),
......
...@@ -106,16 +106,17 @@ class PrefetchDataZMQ(ProxyDataFlow): ...@@ -106,16 +106,17 @@ class PrefetchDataZMQ(ProxyDataFlow):
Prefetch data from a DataFlow using multiple processes, with ZMQ for Prefetch data from a DataFlow using multiple processes, with ZMQ for
communication. communication.
A local directory is needed to put the ZMQ pipes.
You can set this with env var $TENSORPACK_PIPEDIR if you're running on non-local FS such as NFS or GlusterFS.
Note that this dataflow is not fork-safe. You cannot nest this dataflow Note that this dataflow is not fork-safe. You cannot nest this dataflow
into another PrefetchDataZMQ or PrefetchData. into another PrefetchDataZMQ or PrefetchData.
""" """
def __init__(self, ds, nr_proc=1, pipedir=None, hwm=50): def __init__(self, ds, nr_proc=1, hwm=50):
""" """
Args: Args:
ds (DataFlow): input DataFlow. ds (DataFlow): input DataFlow.
nr_proc (int): number of processes to use. nr_proc (int): number of processes to use.
pipedir (str): a local directory where the pipes should be put.
Useful if you're running on non-local FS such as NFS or GlusterFS.
hwm (int): the zmq "high-water mark" for both sender and receiver. hwm (int): the zmq "high-water mark" for both sender and receiver.
""" """
super(PrefetchDataZMQ, self).__init__(ds) super(PrefetchDataZMQ, self).__init__(ds)
...@@ -128,8 +129,7 @@ class PrefetchDataZMQ(ProxyDataFlow): ...@@ -128,8 +129,7 @@ class PrefetchDataZMQ(ProxyDataFlow):
self.context = zmq.Context() self.context = zmq.Context()
self.socket = self.context.socket(zmq.PULL) self.socket = self.context.socket(zmq.PULL)
if pipedir is None: pipedir = os.environ.get('TENSORPACK_PIPEDIR', '.')
pipedir = os.environ.get('TENSORPACK_PIPEDIR', '.')
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(hwm) self.socket.set_hwm(hwm)
......
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