Commit 145fb01d authored by Yuxin Wu's avatar Yuxin Wu

small fix

parent 2168a020
## Holistically-Nested Edge Detection
Reproduce the HED paper by Saining Xie and Zhuowen Tu. See [https://arxiv.org/abs/1504.06375](https://arxiv.org/abs/1504.06375).
...@@ -22,9 +22,10 @@ HED is a fully-convolutional architecture. This code generally would also work ...@@ -22,9 +22,10 @@ HED is a fully-convolutional architecture. This code generally would also work
for other FCN tasks such as semantic segmentation and detection. for other FCN tasks such as semantic segmentation and detection.
Usage: Usage:
This script only needs the original BSDS dataset and applies augmentation on the fly.
It will automatically download the dataset to $TENSORPACK_DATASET/ if not there.
It requires pretrained vgg16 model. See the docs in `examples/load-vgg16.py` It requires pretrained vgg16 model. See the docs in `examples/load-vgg16.py`
for instructions to convert from vgg16 caffe model. for instructions to convert from vgg16 caffe model.
It only needs the original BSDS dataset and applies augmentation on the fly.
To view augmented images: To view augmented images:
./hed.py --view ./hed.py --view
...@@ -35,11 +36,11 @@ Usage: ...@@ -35,11 +36,11 @@ Usage:
To inference (produce heatmap at each level): To inference (produce heatmap at each level):
./hed.py --load pretrained.model --run a.jpg ./hed.py --load pretrained.model --run a.jpg
To view the loss: To view the loss curve:
cat train_log/hed/stat.json | jq '.[] | \ cat train_log/hed/stat.json | jq '.[] |
[.xentropy1,.xentropy2,.xentropy3,.xentropy4,.xentropy5,.xentropy6] | \ [.xentropy1,.xentropy2,.xentropy3,.xentropy4,.xentropy5,.xentropy6] |
map(tostring) | join("\t") | .' -r | \ map(tostring) | join("\t") | .' -r | \
../../scripts/plot-point.py -c 'y,y,y,y,y,y' --legend 1,2,3,4,5,final ../../scripts/plot-point.py --legend 1,2,3,4,5,final --decay 0.8
""" """
BATCH_SIZE = 1 BATCH_SIZE = 1
...@@ -54,6 +55,7 @@ class Model(ModelDesc): ...@@ -54,6 +55,7 @@ class Model(ModelDesc):
def _build_graph(self, input_vars, is_training): def _build_graph(self, input_vars, is_training):
image, edgemap = input_vars image, edgemap = input_vars
# TODO fix this
edgemap = tf.identity(edgemap, name='edgemap-tmp') edgemap = tf.identity(edgemap, name='edgemap-tmp')
image = image - tf.constant([104, 116, 122], dtype='float32') image = image - tf.constant([104, 116, 122], dtype='float32')
...@@ -139,12 +141,10 @@ def get_data(name): ...@@ -139,12 +141,10 @@ def get_data(name):
imgaug.Flip(horiz=True), imgaug.Flip(horiz=True),
imgaug.Flip(vert=True), imgaug.Flip(vert=True),
] ]
ds = AugmentImageComponents(ds, shape_aug, (0, 1))
else: else:
# this is the original image shape in bsds # the original image shape (320x480) in bsds is already a multiple of 16
IMAGE_SHAPE = (320, 480) pass
#shape_aug = [imgaug.RandomCrop(IMAGE_SHAPE)]
shape_aug = []
ds = AugmentImageComponents(ds, shape_aug, (0, 1))
def f(m): def f(m):
m[m>=0.49] = 1 m[m>=0.49] = 1
m[m<0.49] = 0 m[m<0.49] = 0
...@@ -185,7 +185,6 @@ def get_config(): ...@@ -185,7 +185,6 @@ def get_config():
return TrainConfig( return TrainConfig(
dataset=dataset_train, dataset=dataset_train,
optimizer=tf.train.AdamOptimizer(lr, epsilon=1e-3), optimizer=tf.train.AdamOptimizer(lr, epsilon=1e-3),
#optimizer=tf.train.MomentumOptimizer(lr, 0.9),
callbacks=Callbacks([ callbacks=Callbacks([
StatPrinter(), StatPrinter(),
ModelSaver(), ModelSaver(),
...@@ -215,7 +214,6 @@ def run(model_path, image_path): ...@@ -215,7 +214,6 @@ def run(model_path, image_path):
cv2.imwrite("out{}.png".format( cv2.imwrite("out{}.png".format(
'-fused' if k == 5 else str(k+1)), pred * 255) '-fused' if k == 5 else str(k+1)), pred * 255)
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--gpu', help='comma separated list of GPU(s) to use.') # nargs='*' in multi mode parser.add_argument('--gpu', help='comma separated list of GPU(s) to use.') # nargs='*' in multi mode
...@@ -227,18 +225,15 @@ if __name__ == '__main__': ...@@ -227,18 +225,15 @@ if __name__ == '__main__':
if args.view: if args.view:
ds = get_data('train') ds = get_data('train')
view_data(ds) view_data(ds)
sys.exit() elif args.run:
if args.run:
run(args.load, args.run) run(args.load, args.run)
sys.exit() else:
if args.gpu:
if args.gpu: os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu
os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu
config = get_config()
config = get_config() if args.load:
if args.load: config.session_init = get_model_loader(args.load)
config.session_init = get_model_loader(args.load) if args.gpu:
if args.gpu: config.nr_tower = len(args.gpu.split(','))
config.nr_tower = len(args.gpu.split(',')) SyncMultiGPUTrainer(config).train()
SyncMultiGPUTrainer(config).train()
...@@ -77,4 +77,4 @@ if __name__ == '__main__': ...@@ -77,4 +77,4 @@ if __name__ == '__main__':
r, o = env.action(act) r, o = env.action(act)
env.current_state() env.current_state()
if r != 0 or o: if r != 0 or o:
print r, o print(r, o)
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