Commit c51df958 authored by Yuxin Wu's avatar Yuxin Wu

misc change in hed

parent 2a444073
...@@ -107,6 +107,11 @@ class Model(ModelDesc): ...@@ -107,6 +107,11 @@ class Model(ModelDesc):
wrong = tf.cast(tf.not_equal(pred, edgemap), tf.float32) wrong = tf.cast(tf.not_equal(pred, edgemap), tf.float32)
wrong = tf.reduce_mean(wrong, name='train_error') wrong = tf.reduce_mean(wrong, name='train_error')
wd_w = tf.train.exponential_decay(2e-4, get_global_step_var(),
80000, 0.7, True)
wd_cost = tf.mul(wd_w, regularize_cost('.*/W', tf.nn.l2_loss), name='wd_cost')
costs.append(wd_cost)
add_moving_summary(costs + [wrong]) add_moving_summary(costs + [wrong])
add_param_summary([('.*/W', ['histogram'])]) # monitor W add_param_summary([('.*/W', ['histogram'])]) # monitor W
self.cost = tf.add_n(costs, name='cost') self.cost = tf.add_n(costs, name='cost')
...@@ -142,7 +147,7 @@ def get_data(name): ...@@ -142,7 +147,7 @@ def get_data(name):
else: else:
# the original image shape (321x481) in BSDS is not a multiple of 16 # the original image shape (321x481) in BSDS is not a multiple of 16
IMAGE_SHAPE = (320, 480) IMAGE_SHAPE = (320, 480)
shape_aug = [imgaug.RandomCrop(IMAGE_SHAPE)] shape_aug = [imgaug.CenterCrop(IMAGE_SHAPE)]
ds = AugmentImageComponents(ds, shape_aug, (0, 1)) ds = AugmentImageComponents(ds, shape_aug, (0, 1))
def f(m): def f(m):
...@@ -177,7 +182,7 @@ def view_data(): ...@@ -177,7 +182,7 @@ def view_data():
def get_config(): def get_config():
logger.auto_set_dir() logger.auto_set_dir()
dataset_train = get_data('train') dataset_train = get_data('train')
step_per_epoch = dataset_train.size() * 20 step_per_epoch = dataset_train.size() * 100
dataset_val = get_data('val') dataset_val = get_data('val')
#dataset_test = get_data('test') #dataset_test = get_data('test')
...@@ -190,13 +195,14 @@ def get_config(): ...@@ -190,13 +195,14 @@ def get_config():
callbacks=Callbacks([ callbacks=Callbacks([
StatPrinter(), StatPrinter(),
ModelSaver(), ModelSaver(),
ScheduledHyperParamSetter('learning_rate', [(25, 3e-6)]),
HumanHyperParamSetter('learning_rate'), HumanHyperParamSetter('learning_rate'),
InferenceRunner(dataset_val, InferenceRunner(dataset_val,
BinaryClassificationStats('prediction', 'edgemap')) BinaryClassificationStats('prediction', 'edgemap'))
]), ]),
model=Model(), model=Model(),
step_per_epoch=step_per_epoch, step_per_epoch=step_per_epoch,
max_epoch=500, max_epoch=100,
) )
def run(model_path, image_path): def run(model_path, image_path):
......
...@@ -73,16 +73,14 @@ class BSDS500(RNGDataFlow): ...@@ -73,16 +73,14 @@ class BSDS500(RNGDataFlow):
gt = loadmat(gt_file)['groundTruth'][0] gt = loadmat(gt_file)['groundTruth'][0]
n_annot = gt.shape[0] n_annot = gt.shape[0]
gt = sum(gt[k]['Boundaries'][0][0] for k in range(n_annot)) gt = sum(gt[k]['Boundaries'][0][0] for k in range(n_annot))
#gt[gt <= 2] = 0
gt = gt.astype('float32') gt = gt.astype('float32')
gt /= np.max(gt) gt *= 1.0 / n_annot
if gt.shape[0] > gt.shape[1]: if gt.shape[0] > gt.shape[1]:
gt = gt.transpose() gt = gt.transpose()
assert gt.shape == (IMG_H, IMG_W) assert gt.shape == (IMG_H, IMG_W)
self.data[idx] = im self.data[idx] = im
self.label[idx] = gt self.label[idx] = gt
#self.label[self.label<0.9] = 0
def size(self): def size(self):
return self.data.shape[0] return self.data.shape[0]
......
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