-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Verify the correctness of SSD loss. #8626
Projects
Comments
This was referenced Feb 28, 2018
Verify confidence gradientsThe confidence gradients of one data:
The absolute error: about 0.00000x%
# omit the other code
loc_grad_var = fluid.framework.get_var('reshape_6.tmp_0@GRAD')
conf_grad_var = fluid.framework.get_var('reshape_1.tmp_0@GRAD')
conf_loss_grad_var = fluid.framework.get_var('softmax_with_cross_entropy_1.tmp_1@GRAD')
fetch = [loss, loc_grad_var, conf_grad_var, conf_loss_grad_var]
loss_v, loc_grad_v, conf_grad_v, conf_loss_grad_v = exe.run(fluid.default_main_program(), feed=feeding, fetch_list=fetch)
conf_loss_grad_v = np.array(conf_loss_grad_v).astype(np.float32).flatten()
indices = np.where(conf_loss_grad_v > 0.)[0]
print('-------- fluid gradients ------')
print 'conf gradients', conf_grad_v[indices, :]
print('-------- caffe gradient ------')
expect_conf_g = load('data/conf_diff_data', conf_grad_v.shape)
print 'conf gradient', expect_conf_g[indices, :] |
Verify localization gradientsThe localization gradients of one data:
loc_grad_var = fluid.framework.get_var('reshape_6.tmp_0@GRAD')
conf_grad_var = fluid.framework.get_var('reshape_1.tmp_0@GRAD')
conf_loss_grad_var = fluid.framework.get_var('softmax_with_cross_entropy_1.tmp_1@GRAD')
loc_loss_grad_var = fluid.framework.get_var('smooth_l1_loss_0.tmp_1@GRAD')
fetch = [loss, loc_grad_var, conf_grad_var, conf_loss_grad_var, loc_loss_grad_var]
loss_v, loc_grad_v, conf_grad_v, conf_loss_grad_v, loc_loss_grad_v = exe.run(fluid.default_main_program(), feed=feeding, fetch_list=fetch)
loc_loss_grad_v = np.array(loc_loss_grad_v).astype(np.float32).flatten()
loc_indices = np.where(loc_loss_grad_v > 0.)[0]
print loc_indices
print('-------- fluid gradients ------')
print 'loc gradients sum', np.sum(loc_grad_v[loc_indices, :])
f1 = open("fluid_loc.txt", "w")
print >> f1, 'loc gradients', loc_grad_v[loc_indices, :]
f1.close()
print('-------- caffe gradient ------')
expect_loc_g = load('data/loc_diff_data', loc_grad_v.shape)
print 'loc gradient sum', np.sum(expect_loc_g[loc_indices, :])
f2 = open("caffe_loc.txt", "w")
print >> f2, 'loc gradient', expect_loc_g[loc_indices, :]
f2.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Target: this verification is to make the loss consistent with Caffe.
Method: in caffe, we train the SSD model on VOC dataset by following the tutorial , and save the inputs and outputs of one mini-batch in multibox_loss_layer of caffe, then load them in Fluid testing code.
The saving code in caffe aftern line https://github.com/weiliu89/caffe/blob/ssd/src/caffe/layers/multibox_loss_layer.cpp#L151:
Testing code in Fluid:
So the forward loss is correct.
The text was updated successfully, but these errors were encountered: