Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smoothL1的问题 #10638

Closed
dyning opened this issue May 14, 2018 · 1 comment
Closed

smoothL1的问题 #10638

dyning opened this issue May 14, 2018 · 1 comment
Assignees
Labels

Comments

@dyning
Copy link
Contributor

dyning commented May 14, 2018

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()
@dyning
Copy link
Contributor Author

dyning commented Jun 8, 2018

赞!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants