smoothL1的问题
Created by: dyning
smooth L1,如果使用inside_weight和outside_weight,并行运行会卡死。测试程序如下:
import paddle
import paddle.fluid as fluid
import sys, os
import time
import numpy as np
import math
import random
def reader_test():
def reader():
index = range(0, 10000)
random.shuffle(index)
for idx in index:
image = np.random.rand(3, 224, 224)
loc = np.random.rand(4)
weight = np.random.rand(4)
yield image, loc, weight
return reader
def main():
data = fluid.layers.data(name='data', shape=[3, 224, 224], dtype='float32')
bbox_targets = fluid.layers.data(name='bbox_targets', shape=[4], dtype='float32')
bbox_loss_weights = fluid.layers.data(name='bbox_loss_weights', shape=[4], dtype='float32')
fea_fc = fluid.layers.fc(input=data, size=1024, act='relu')
fc_loc = fluid.layers.fc(input=fea_fc, size=4, act='relu')
#loss_loc = fluid.layers.smooth_l1(fc_loc, bbox_targets)
loss_loc = fluid.layers.smooth_l1(fc_loc, bbox_targets, inside_weight=bbox_loss_weights, outside_weight=bbox_loss_weights)
avg_loss = fluid.layers.mean(x=loss_loc)
bd = [80000]
lr = [0.001, 0.0001]
optimizer = fluid.optimizer.Momentum(learning_rate=fluid.layers.piecewise_decay(boundaries=bd, values=lr), momentum=0.9,
regularization=fluid.regularizer.L2Decay(1e-4))
opts = optimizer.minimize(avg_loss)
place = fluid.CUDAPlace(0)
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
train_reader = paddle.batch(reader_test(), batch_size=16)
feeder = fluid.DataFeeder(place=place, feed_list=[data, bbox_targets, bbox_loss_weights])
train_exe = fluid.ParallelExecutor(use_cuda=True, loss_name=avg_loss.name)
for pass_id in range(0, 20):
for batch_id, blobs in enumerate(train_reader()):
print batch_id
train_exe.run([avg_loss.name], feed=feeder.feed(blobs))
#exe.run(fluid.default_main_program(), feed=feeder.feed(blobs), fetch_list=[])
print "ok"
if __name__ == '__main__':
main()