Open hzxie opened 5 years ago
#ifndef CAFFE_CHAMFER_DISTANCE_LAYER_HPP_
#define CAFFE_CHAMFER_DISTANCE_LAYER_HPP_
#include <vector>
#include "caffe/blob.hpp"
#include "caffe/layer.hpp"
#include "caffe/proto/caffe.pb.h"
#include "caffe/layers/loss_layer.hpp"
namespace caffe {
template <typename Dtype>
class ChamferDistanceLossLayer : public LossLayer<Dtype> {
public:
explicit ChamferDistanceLossLayer(const LayerParameter& param)
: LossLayer<Dtype>(param) {}
virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual inline const char* type() const { return "ChamferDistanceLoss"; }
/**
* Unlike most loss layers, in the ChamferDistanceLossLayer we can
* backpropagate to both inputs -- override to return true and always allow
* force_backward.
*/
virtual inline bool AllowForceBackward(const int bottom_index) const {
return true;
}
protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down,
const vector<Blob<Dtype>*>& bottom);
virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down,
const vector<Blob<Dtype>*>& bottom);
Blob<int> indexes1_;
Blob<int> indexes2_;
};
} // namespace caffe
#endif // CAFFE_CHAMFER_DISTANCE_LAYER_HPP_
#include <iostream>
#include <vector>
#include "caffe/layers/chamfer_distance_loss_layer.hpp"
#include "caffe/util/math_functions.hpp"
namespace caffe {
template <typename Dtype>
void ChamferDistanceLossLayer<Dtype>::LayerSetUp(
const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {
LossLayer<Dtype>::LayerSetUp(bottom, top);
CHECK_EQ(bottom[0]->num(), bottom[1]->num());
CHECK_EQ(bottom[0]->height(), 3);
CHECK_EQ(bottom[1]->height(), 3);
CHECK_EQ(bottom[1]->width(), 1);
CHECK_EQ(bottom[1]->width(), 1);
}
template <typename Dtype>
void ChamferDistanceLossLayer<Dtype>::Reshape(
const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {
LossLayer<Dtype>::Reshape(bottom, top);
indexes1_.Reshape(bottom[0]->num(), bottom[0]->channels(), 1, 1);
indexes2_.Reshape(bottom[1]->num(), bottom[1]->channels(), 1, 1);
}
template <typename Dtype>
void ChamferDistanceLossLayer<Dtype>::Forward_cpu(
const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {
Blob<Dtype> dist1(bottom[0]->num(), bottom[0]->channels(), 1, 1);
Blob<Dtype> dist2(bottom[1]->num(), bottom[1]->channels(), 1, 1);
Dtype* m_dist1 = dist1.mutable_cpu_data();
Dtype* m_dist2 = dist2.mutable_cpu_data();
int* indexes1 = indexes1_.mutable_cpu_data();
int* indexes2 = indexes2_.mutable_cpu_data();
const int num = bottom[0]->num();
const int n_points1 = bottom[0]->channels();
const int n_points2 = bottom[1]->channels();
for (int i = 0; i < num; ++i) {
for (int j = 0; j < n_points1; ++j) {
Dtype _min_distance(1e12);
for (int k = 0; k < n_points2; ++k) {
Dtype x1 = bottom[0]->data_at(i, j, 0, 0);
Dtype y1 = bottom[0]->data_at(i, j, 1, 0);
Dtype z1 = bottom[0]->data_at(i, j, 2, 0);
Dtype x2 = bottom[1]->data_at(i, k, 0, 0);
Dtype y2 = bottom[1]->data_at(i, k, 1, 0);
Dtype z2 = bottom[1]->data_at(i, k, 2, 0);
Dtype dx = x1 - x2;
Dtype dy = y1 - y2;
Dtype dz = z1 - z2;
Dtype dist = dx * dx + dy * dy + dz * dz;
if (dist < _min_distance) {
_min_distance = dist;
indexes1[i * n_points1 + j] = k;
}
}
m_dist1[i * n_points1 + j] += _min_distance / n_points1;
}
for (int j = 0; j < n_points2; ++j) {
Dtype _min_distance(1e12);
for (int k = 0; k < n_points1; ++k) {
Dtype x1 = bottom[1]->data_at(i, j, 0, 0);
Dtype y1 = bottom[1]->data_at(i, j, 1, 0);
Dtype z1 = bottom[1]->data_at(i, j, 2, 0);
Dtype x2 = bottom[0]->data_at(i, k, 0, 0);
Dtype y2 = bottom[0]->data_at(i, k, 1, 0);
Dtype z2 = bottom[0]->data_at(i, k, 2, 0);
Dtype dx = x1 - x2;
Dtype dy = y1 - y2;
Dtype dz = z1 - z2;
Dtype dist = dx * dx + dy * dy + dz * dz;
if (dist < _min_distance) {
_min_distance = dist;
indexes2[i * n_points2 + j] = k;
}
}
m_dist2[i * n_points2 + j] += _min_distance / n_points2;
}
}
Dtype loss1 = caffe_cpu_asum(dist1.count(), dist1.cpu_data()) / num;
Dtype loss2 = caffe_cpu_asum(dist2.count(), dist2.cpu_data()) / num;
top[0]->mutable_cpu_data()[0] = loss1 + loss2;
}
template <typename Dtype>
void ChamferDistanceLossLayer<Dtype>::Backward_cpu(
const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down,
const vector<Blob<Dtype>*>& bottom) {
const int num = bottom[0]->num();
const int n_points1 = bottom[0]->channels();
const int n_points2 = bottom[1]->channels();
Dtype grad_dist1 = Dtype(1.0) / n_points1 / num;
Dtype grad_dist2 = Dtype(1.0) / n_points2 / num;
Dtype* diff1 = bottom[0]->mutable_cpu_diff();
Dtype* diff2 = bottom[1]->mutable_cpu_diff();
for (int i = 0; i < num; ++i) {
for (int j = 0; j < n_points1; ++j) {
int k = indexes1_.data_at(i, j, 0, 0);
Dtype x1 = bottom[0]->data_at(i, j, 0, 0);
Dtype y1 = bottom[0]->data_at(i, j, 1, 0);
Dtype z1 = bottom[0]->data_at(i, j, 2, 0);
Dtype x2 = bottom[1]->data_at(i, k, 0, 0);
Dtype y2 = bottom[1]->data_at(i, k, 1, 0);
Dtype z2 = bottom[1]->data_at(i, k, 2, 0);
Dtype grad = grad_dist1 * 2;
diff1[(i * n_points1 + j) * 3 + 0] += grad * (x1 - x2);
diff1[(i * n_points1 + j) * 3 + 1] += grad * (y1 - y2);
diff1[(i * n_points1 + j) * 3 + 2] += grad * (z1 - z2);
diff2[(i * n_points2 + k) * 3 + 0] += grad * (x2 - x1);
diff2[(i * n_points2 + k) * 3 + 1] += grad * (y2 - y1);
diff2[(i * n_points2 + k) * 3 + 2] += grad * (z2 - z1);
}
}
for (int i = 0; i < num; ++i) {
for (int j = 0; j < n_points2; ++j) {
int k = indexes2_.data_at(i, j, 0, 0);
Dtype x1 = bottom[1]->data_at(i, j, 0, 0);
Dtype y1 = bottom[1]->data_at(i, j, 1, 0);
Dtype z1 = bottom[1]->data_at(i, j, 2, 0);
Dtype x2 = bottom[0]->data_at(i, k, 0, 0);
Dtype y2 = bottom[0]->data_at(i, k, 1, 0);
Dtype z2 = bottom[0]->data_at(i, k, 2, 0);
Dtype grad = grad_dist2 * 2;
diff2[(i * n_points2 + j) * 3 + 0] += grad * (x1 - x2);
diff2[(i * n_points2 + j) * 3 + 1] += grad * (y1 - y2);
diff2[(i * n_points2 + j) * 3 + 2] += grad * (z1 - z2);
diff1[(i * n_points1 + k) * 3 + 0] += grad * (x2 - x1);
diff1[(i * n_points1 + k) * 3 + 1] += grad * (y2 - y1);
diff1[(i * n_points1 + k) * 3 + 2] += grad * (z2 - z1);
}
}
}
#ifdef CPU_ONLY
STUB_GPU(ChamferDistanceLossLayer);
#endif
INSTANTIATE_CLASS(ChamferDistanceLossLayer);
REGISTER_LAYER_CLASS(ChamferDistanceLoss);
} // namespace caffe
#include <stdio.h>
#include <vector>
#include "gtest/gtest.h"
#include "caffe/blob.hpp"
#include "caffe/common.hpp"
#include "caffe/filler.hpp"
#include "caffe/layers/chamfer_distance_loss_layer.hpp"
#include "caffe/test/test_caffe_main.hpp"
#include "caffe/test/test_gradient_check_util.hpp"
namespace caffe {
template <typename TypeParam>
class ChamferDistanceLossLayerTest : public MultiDeviceTest<TypeParam> {
typedef typename TypeParam::Dtype Dtype;
protected:
ChamferDistanceLossLayerTest()
: blob_bottom_ptcloud_(new Blob<Dtype>(2, 10, 3, 1)),
blob_bottom_gtcloud_(new Blob<Dtype>(2, 10, 3, 1)),
blob_top_loss_(new Blob<Dtype>()) {
Caffe::set_random_seed(1701);
FillerParameter filler_param;
UniformFiller<Dtype> filler(filler_param);
// filler.Fill(this->blob_bottom_ptcloud_);
// filler.Fill(this->blob_bottom_gtcloud_);
Dtype* ptcloud_ = blob_bottom_ptcloud_->mutable_cpu_data();
Dtype* gtcloud_ = blob_bottom_gtcloud_->mutable_cpu_data();
ptcloud_[0] = 0.4011; ptcloud_[1] = 0.2908; ptcloud_[2] = 0.3521;
ptcloud_[3] = 0.0861; ptcloud_[4] = 0.8777; ptcloud_[5] = 0.4353;
ptcloud_[6] = 0.7420; ptcloud_[7] = 0.1549; ptcloud_[8] = 0.8189;
ptcloud_[9] = 0.3323; ptcloud_[10] = 0.4617; ptcloud_[11] = 0.2126;
ptcloud_[12] = 0.2867; ptcloud_[13] = 0.9608; ptcloud_[14] = 0.6667;
ptcloud_[15] = 0.1773; ptcloud_[16] = 0.5807; ptcloud_[17] = 0.0388;
ptcloud_[18] = 0.4252; ptcloud_[19] = 0.6412; ptcloud_[20] = 0.6042;
ptcloud_[21] = 0.7260; ptcloud_[22] = 0.5044; ptcloud_[23] = 0.8364;
ptcloud_[24] = 0.7606; ptcloud_[25] = 0.0383; ptcloud_[26] = 0.2995;
ptcloud_[27] = 0.3635; ptcloud_[28] = 0.5297; ptcloud_[29] = 0.2056;
ptcloud_[30] = 0.2465; ptcloud_[31] = 0.2190; ptcloud_[32] = 0.4713;
ptcloud_[33] = 0.2807; ptcloud_[34] = 0.0673; ptcloud_[35] = 0.5035;
ptcloud_[36] = 0.1563; ptcloud_[37] = 0.4924; ptcloud_[38] = 0.3246;
ptcloud_[39] = 0.0118; ptcloud_[40] = 0.4919; ptcloud_[41] = 0.7165;
ptcloud_[42] = 0.3805; ptcloud_[43] = 0.4503; ptcloud_[44] = 0.0220;
ptcloud_[45] = 0.6650; ptcloud_[46] = 0.7816; ptcloud_[47] = 0.0317;
ptcloud_[48] = 0.5174; ptcloud_[49] = 0.9315; ptcloud_[50] = 0.3767;
ptcloud_[51] = 0.6830; ptcloud_[52] = 0.9195; ptcloud_[53] = 0.3598;
ptcloud_[54] = 0.1752; ptcloud_[55] = 0.6147; ptcloud_[56] = 0.8423;
ptcloud_[57] = 0.9798; ptcloud_[58] = 0.8040; ptcloud_[59] = 0.7357;
gtcloud_[0] = 0.9321; gtcloud_[1] = 0.7667; gtcloud_[2] = 0.2552;
gtcloud_[3] = 0.7745; gtcloud_[4] = 0.1306; gtcloud_[5] = 0.2459;
gtcloud_[6] = 0.2194; gtcloud_[7] = 0.3606; gtcloud_[8] = 0.9956;
gtcloud_[9] = 0.4877; gtcloud_[10] = 0.2506; gtcloud_[11] = 0.1692;
gtcloud_[12] = 0.5293; gtcloud_[13] = 0.4913; gtcloud_[14] = 0.3616;
gtcloud_[15] = 0.6573; gtcloud_[16] = 0.5852; gtcloud_[17] = 0.2728;
gtcloud_[18] = 0.0400; gtcloud_[19] = 0.3716; gtcloud_[20] = 0.4207;
gtcloud_[21] = 0.6753; gtcloud_[22] = 0.2750; gtcloud_[23] = 0.8677;
gtcloud_[24] = 0.9813; gtcloud_[25] = 0.7300; gtcloud_[26] = 0.1378;
gtcloud_[27] = 0.7216; gtcloud_[28] = 0.7457; gtcloud_[29] = 0.4421;
gtcloud_[30] = 0.3020; gtcloud_[31] = 0.9361; gtcloud_[32] = 0.7699;
gtcloud_[33] = 0.5319; gtcloud_[34] = 0.1045; gtcloud_[35] = 0.0440;
gtcloud_[36] = 0.5918; gtcloud_[37] = 0.5900; gtcloud_[38] = 0.8566;
gtcloud_[39] = 0.5447; gtcloud_[40] = 0.0098; gtcloud_[41] = 0.4900;
gtcloud_[42] = 0.8860; gtcloud_[43] = 0.1312; gtcloud_[44] = 0.6319;
gtcloud_[45] = 0.0322; gtcloud_[46] = 0.6574; gtcloud_[47] = 0.8497;
gtcloud_[48] = 0.0314; gtcloud_[49] = 0.3995; gtcloud_[50] = 0.6097;
gtcloud_[51] = 0.1369; gtcloud_[52] = 0.4054; gtcloud_[53] = 0.4159;
gtcloud_[54] = 0.1296; gtcloud_[55] = 0.2437; gtcloud_[56] = 0.9193;
gtcloud_[57] = 0.5789; gtcloud_[58] = 0.0539; gtcloud_[59] = 0.0890;
blob_bottom_vec_.push_back(blob_bottom_ptcloud_);
blob_bottom_vec_.push_back(blob_bottom_gtcloud_);
blob_top_vec_.push_back(blob_top_loss_);
}
virtual ~ChamferDistanceLossLayerTest() {
delete blob_bottom_ptcloud_;
delete blob_bottom_gtcloud_;
delete blob_top_loss_;
}
Blob<Dtype>* const blob_bottom_ptcloud_;
Blob<Dtype>* const blob_bottom_gtcloud_;
Blob<Dtype>* const blob_top_loss_;
vector<Blob<Dtype>*> blob_bottom_vec_;
vector<Blob<Dtype>*> blob_top_vec_;
};
TYPED_TEST_CASE(ChamferDistanceLossLayerTest, TestDtypesAndDevices);
TYPED_TEST(ChamferDistanceLossLayerTest, TestForward) {
typedef typename TypeParam::Dtype Dtype;
LayerParameter layer_param;
ChamferDistanceLossLayer<Dtype> layer(layer_param);
layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);
const Dtype cd_loss =
layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);
Dtype loss(0);
const int num = this->blob_bottom_gtcloud_->num();
const int n_points1 = this->blob_bottom_ptcloud_->channels();
const int n_points2 = this->blob_bottom_gtcloud_->channels();
for (int i = 0; i < num; ++i) {
Dtype min_distance1(0);
Dtype min_distance2(0);
for (int j = 0; j < n_points1; ++j) {
Dtype _min_distance(1e12);
for (int k = 0; k < n_points2; ++k) {
Dtype x1 = this->blob_bottom_ptcloud_->data_at(i, j, 0, 0);
Dtype y1 = this->blob_bottom_ptcloud_->data_at(i, j, 1, 0);
Dtype z1 = this->blob_bottom_ptcloud_->data_at(i, j, 2, 0);
Dtype x2 = this->blob_bottom_gtcloud_->data_at(i, k, 0, 0);
Dtype y2 = this->blob_bottom_gtcloud_->data_at(i, k, 1, 0);
Dtype z2 = this->blob_bottom_gtcloud_->data_at(i, k, 2, 0);
Dtype dx = x1 - x2;
Dtype dy = y1 - y2;
Dtype dz = z1 - z2;
Dtype dist = dx * dx + dy * dy + dz * dz;
if (dist < _min_distance) {
_min_distance = dist;
}
}
min_distance1 += _min_distance;
}
for (int j = 0; j < n_points2; ++j) {
Dtype _min_distance(1e12);
for (int k = 0; k < n_points1; ++k) {
Dtype x1 = this->blob_bottom_gtcloud_->data_at(i, j, 0, 0);
Dtype y1 = this->blob_bottom_gtcloud_->data_at(i, j, 1, 0);
Dtype z1 = this->blob_bottom_gtcloud_->data_at(i, j, 2, 0);
Dtype x2 = this->blob_bottom_ptcloud_->data_at(i, k, 0, 0);
Dtype y2 = this->blob_bottom_ptcloud_->data_at(i, k, 1, 0);
Dtype z2 = this->blob_bottom_ptcloud_->data_at(i, k, 2, 0);
Dtype dx = x1 - x2;
Dtype dy = y1 - y2;
Dtype dz = z1 - z2;
Dtype dist = dx * dx + dy * dy + dz * dz;
if (dist < _min_distance) {
_min_distance = dist;
}
}
min_distance2 += _min_distance;
}
min_distance1 /= n_points1;
min_distance2 /= n_points2;
loss += min_distance1 + min_distance2;
}
loss /= num;
std::cout << "loss = " << loss << std::endl;
EXPECT_NEAR(cd_loss, loss, 1e-5);
}
// Disabled due to the bugs in GradientChecker.
// The gradient of ChamferDistanceLoss has the same output as the PyTorch
// version.
TYPED_TEST(ChamferDistanceLossLayerTest, TestGradient) {
typedef typename TypeParam::Dtype Dtype;
LayerParameter layer_param;
ChamferDistanceLossLayer<Dtype> layer(layer_param);
layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);
GradientChecker<Dtype> checker(1e-2, 1e-2, 1701);
checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,
this->blob_top_vec_);
}
} // namespace caffe
Here's the code for testing autograd and PyTorch:
import numpy
import jax.numpy as np
import torch
from jax import grad, jit
x = numpy.array([0.4011, 0.2908, 0.3521, 0.0861, 0.8777, 0.4353,
0.7420, 0.1549, 0.8189, 0.3323, 0.4617, 0.2126,
0.2867, 0.9608, 0.6667, 0.1773, 0.5807, 0.0388,
0.4252, 0.6412, 0.6042, 0.7260, 0.5044, 0.8364,
0.7606, 0.0383, 0.2995, 0.3635, 0.5297, 0.2056,
0.2465, 0.2190, 0.4713, 0.2807, 0.0673, 0.5035,
0.1563, 0.4924, 0.3246, 0.0118, 0.4919, 0.7165,
0.3805, 0.4503, 0.0220, 0.6650, 0.7816, 0.0317,
0.5174, 0.9315, 0.3767, 0.6830, 0.9195, 0.3598,
0.1752, 0.6147, 0.8423, 0.9798, 0.8040, 0.7357]).reshape(2, 10, 3).astype(np.float32)
y = numpy.array([0.9321, 0.7667, 0.2552, 0.7745, 0.1306, 0.2459,
0.2194, 0.3606, 0.9956, 0.4877, 0.2506, 0.1692,
0.5293, 0.4913, 0.3616, 0.6573, 0.5852, 0.2728,
0.0400, 0.3716, 0.4207, 0.6753, 0.2750, 0.8677,
0.9813, 0.7300, 0.1378, 0.7216, 0.7457, 0.4421,
0.3020, 0.9361, 0.7699, 0.5319, 0.1045, 0.0440,
0.5918, 0.5900, 0.8566, 0.5447, 0.0098, 0.4900,
0.8860, 0.1312, 0.6319, 0.0322, 0.6574, 0.8497,
0.0314, 0.3995, 0.6097, 0.1369, 0.4054, 0.4159,
0.1296, 0.2437, 0.9193, 0.5789, 0.0539, 0.0890]).reshape(2, 10, 3).astype(np.float32)
xt = torch.from_numpy(x)
yt = torch.from_numpy(y)
xt.requires_grad_(True)
yt.requires_grad_(True)
bs, num_points, points_dim = xt.size()
xx = torch.bmm(xt, xt.transpose(2,1))
yy = torch.bmm(yt, yt.transpose(2,1))
zz = torch.bmm(xt, yt.transpose(2,1))
diag_ind = torch.arange(0, num_points).type(torch.LongTensor)
rx = xx[:, diag_ind, diag_ind].unsqueeze(1).expand_as(xx)
ry = yy[:, diag_ind, diag_ind].unsqueeze(1).expand_as(yy)
P = (rx.transpose(2,1) + ry - 2*zz)
loss = torch.mean(P.min(1)[0]) + torch.mean(P.min(2)[0])
print(loss)
loss.backward(retain_graph=True)
def chamfer_distance(ptcloud1, ptcloud2):
num, n_points, _ = ptcloud1.shape
xx = np.matmul(ptcloud1, ptcloud1.transpose((0, 2, 1)))
yy = np.matmul(ptcloud2, ptcloud2.transpose((0, 2, 1)))
xy = np.matmul(ptcloud1, ptcloud2.transpose((0, 2, 1)))
diag = np.arange(n_points)
rx = xx[:, diag, diag][:, np.newaxis, :].repeat(axis=1, repeats=n_points)
ry = yy[:, diag, diag][:, np.newaxis, :].repeat(axis=1, repeats=n_points)
dist = (rx.transpose((0, 2, 1)) + ry - 2 * xy)
dist1 = np.amin(dist, 1)
dist2 = np.amin(dist, 2)
return np.mean(dist1 + dist2)
_x = np.array(x)
_y = np.array(y)
print(chamfer_distance(x, y))
_grad1 = grad(chamfer_distance, 0)
_grad1(x, y)
print(xt.grad)
_grad2 = grad(chamfer_distance, 1)
_grad2(x, y)
print(yt.grad)
The gradients outputted by autograd (JAX) are as following:
DeviceArray([[[-0.01731999, 0.00804 , 0.03658 ],
[ 0.00461 , 0.05061 , 0.00146 ],
[ 0.01334 , -0.02402001, -0.00975999],
[ 0.00953001, 0.00605 , -0.03571001],
[-0.04349 , 0.02151 , 0.02246 ],
[ 0.01373 , 0.02091 , -0.03819 ],
[-0.01946999, 0.03260002, 0.00133 ],
[ 0.00507 , 0.02294 , -0.00313 ],
[-0.00278001, -0.01846 , 0.01072 ],
[-0.18118 , -0.04160002, -0.0361 ]],
[[ 0.01096 , -0.01864 , 0.00554 ],
[-0.11332999, 0.00511 , -0.01014 ],
[ 0.00388 , 0.0174 , -0.01826 ],
[-0.0157 , 0.0433 , 0.00107999],
[-0.05012 , 0.10880001, -0.0111 ],
[ 0.01331 , 0.06771 , -0.00123 ],
[ 0.02154 , -0.00046 , -0.03932 ],
[ 0.0381 , -0.00166 , -0.04101 ],
[-0.02573999, -0.03821 , 0.00432998],
[ 0.0388 , 0.02140001, -0.01209 ]]], dtype=float32)
DeviceArray([[[ 0.05686 , 0.02370001, 0.00496 ],
[ 0.00278001, 0.01846 , -0.01072 ],
[-0.02058 , -0.02806 , 0.03914 ],
[ 0.01731999, -0.00804 , -0.03658 ],
[ 0.06326999, -0.01970999, 0.02184001],
[ 0.02938 , 0.00555 , 0.00672 ],
[-0.04757 , -0.08053 , 0.05754001],
[-0.01841 , 0.00108 , 0.01289 ],
[ 0.06178 , 0.02003001, -0.00678 ],
[ 0.07313 , -0.01106 , -0.03867001]],
[[-0.04696001, 0.03426002, 0.07309 ],
[ 0.01697001, -0.13687 , 0.00563 ],
[ 0.00285999, -0.02387001, 0.01352 ],
[ 0.0528 , -0.0115 , -0.00269999],
[ 0.06053 , 0.00639 , 0.01284001],
[-0.0286 , 0.00854 , 0.00148 ],
[ 0.00392 , -0.01848 , -0.02135998],
[-0.01484 , 0.00124001, 0.01272 ],
[ 0.01178 , -0.02482 , 0.02028 ],
[ 0.01984 , -0.03964 , 0.0067 ]]], dtype=float32)
The output of PyTorch is:
tensor([[[-0.0173, 0.0080, 0.0366],
[ 0.0046, 0.0506, 0.0015],
[ 0.0133, -0.0240, -0.0098],
[ 0.0095, 0.0060, -0.0357],
[-0.0435, 0.0215, 0.0225],
[ 0.0137, 0.0209, -0.0382],
[-0.0195, 0.0326, 0.0013],
[ 0.0051, 0.0229, -0.0031],
[-0.0028, -0.0185, 0.0107],
[-0.1812, -0.0416, -0.0361]],
[[ 0.0110, -0.0186, 0.0055],
[-0.1133, 0.0051, -0.0101],
[ 0.0039, 0.0174, -0.0183],
[-0.0157, 0.0433, 0.0011],
[-0.0501, 0.1088, -0.0111],
[ 0.0133, 0.0677, -0.0012],
[ 0.0215, -0.0005, -0.0393],
[ 0.0381, -0.0017, -0.0410],
[-0.0257, -0.0382, 0.0043],
[ 0.0388, 0.0214, -0.0121]]])
tensor([[[ 0.0569, 0.0237, 0.0050],
[ 0.0028, 0.0185, -0.0107],
[-0.0206, -0.0281, 0.0391],
[ 0.0173, -0.0080, -0.0366],
[ 0.0633, -0.0197, 0.0218],
[ 0.0294, 0.0056, 0.0067],
[-0.0476, -0.0805, 0.0575],
[-0.0184, 0.0011, 0.0129],
[ 0.0618, 0.0200, -0.0068],
[ 0.0731, -0.0111, -0.0387]],
[[-0.0470, 0.0343, 0.0731],
[ 0.0170, -0.1369, 0.0056],
[ 0.0029, -0.0239, 0.0135],
[ 0.0528, -0.0115, -0.0027],
[ 0.0605, 0.0064, 0.0128],
[-0.0286, 0.0085, 0.0015],
[ 0.0039, -0.0185, -0.0214],
[-0.0148, 0.0012, 0.0127],
[ 0.0118, -0.0248, 0.0203],
[ 0.0198, -0.0396, 0.0067]]])
The output of GradientChecker is:
/include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.036579999999994332, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.036580000000000008,
estimated_gradient evaluates to 0.073159999999994341, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,2; feat = 0.35210000000000002; objective+ = 0.54718473299999992; objective- = 0.54572153300000004
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.050610000000001862, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.050610000000000002,
estimated_gradient evaluates to 0.10122000000000186, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,4; feat = 0.87770000000000004; objective+ = 0.54745533300000004; objective- = 0.54543093300000001
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.013339999999995598, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.013339999999999998,
estimated_gradient evaluates to 0.026679999999995596, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,6; feat = 0.74199999999999999; objective+ = 0.54671993299999988; objective- = 0.54618633299999997
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.024020000000004742, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.024020000000000003,
estimated_gradient evaluates to -0.048040000000004746, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,7; feat = 0.15490000000000004; objective+ = 0.54597273299999993; objective- = 0.54693353300000003
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.035709999999999818, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.035709999999999999,
estimated_gradient evaluates to -0.071419999999999817, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,11; feat = 0.21260000000000004; objective+ = 0.54573893299999998; objective- = 0.54716733299999998
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.043489999999997614, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.043490000000000001,
estimated_gradient evaluates to -0.086979999999997615, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,12; feat = 0.28670000000000001; objective+ = 0.54557333299999999; objective- = 0.54731293299999995
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.021509999999999172, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.021509999999999998,
estimated_gradient evaluates to 0.04301999999999917, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,13; feat = 0.96079999999999999; objective+ = 0.54687333299999996; objective- = 0.54601293299999998
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.022459999999998297, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.022459999999999997,
estimated_gradient evaluates to 0.044919999999998295, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,14; feat = 0.66669999999999996; objective+ = 0.54689233299999995; objective- = 0.54599393299999999
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.01372999999999582, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.013730000000000001,
estimated_gradient evaluates to 0.027459999999995821, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,15; feat = 0.17730000000000004; objective+ = 0.54671773299999993; objective- = 0.54616853300000001
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.020909999999997968, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.020910000000000002,
estimated_gradient evaluates to 0.04181999999999797, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,16; feat = 0.58069999999999999; objective+ = 0.54686133299999995; objective- = 0.54602493299999999
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.038190000000003665, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.038190000000000002,
estimated_gradient evaluates to -0.076380000000003667, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,17; feat = 0.038800000000000001; objective+ = 0.54567933299999993; objective- = 0.54720693300000001
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.019469999999998426, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.019469999999999994,
estimated_gradient evaluates to -0.03893999999999842, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,18; feat = 0.42520000000000002; objective+ = 0.54607373300000006; objective- = 0.54685253300000003
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.032599999999998602, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.03259999999999999,
estimated_gradient evaluates to 0.065199999999998592, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,19; feat = 0.64119999999999999; objective+ = 0.54711513299999992; objective- = 0.54581113299999995
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.022939999999998149, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.022939999999999995,
estimated_gradient evaluates to 0.045879999999998144, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,22; feat = 0.50439999999999996; objective+ = 0.54690193300000001; objective- = 0.54598433300000004
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.018459999999995844, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.018460000000000001,
estimated_gradient evaluates to -0.036919999999995845, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,25; feat = 0.038300000000000001; objective+ = 0.54608393300000002; objective- = 0.54682233299999994
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.0107199999999948, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.010719999999999997,
estimated_gradient evaluates to 0.021439999999994797, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,26; feat = 0.29949999999999999; objective+ = 0.54666753299999993; objective- = 0.54623873300000003
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.18118000000000045, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.18118000000000001,
estimated_gradient evaluates to -0.36236000000000046, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,27; feat = 0.36349999999999999; objective+ = 0.54285953300000001; objective- = 0.55010673300000001
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.041600000000005452, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.04160000000000004,
estimated_gradient evaluates to -0.083200000000005492, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,28; feat = 0.52969999999999995; objective+ = 0.54565113300000001; objective- = 0.54731513300000012
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.036100000000000056, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.036099999999999986,
estimated_gradient evaluates to -0.072200000000000042, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,29; feat = 0.20560000000000003; objective+ = 0.54576113300000006; objective- = 0.54720513300000007
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.010959999999997496, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.010960000000000001,
estimated_gradient evaluates to 0.021919999999997497, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,30; feat = 0.24650000000000002; objective+ = 0.546662333; objective- = 0.54622393300000005
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.018640000000000646, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.01864,
estimated_gradient evaluates to -0.037280000000000646, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,31; feat = 0.21900000000000003; objective+ = 0.54607033299999996; objective- = 0.54681593299999998
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.11333000000000631, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.11332999999999999,
estimated_gradient evaluates to -0.2266600000000063, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,33; feat = 0.28070000000000001; objective+ = 0.54419653299999993; objective- = 0.54872973300000005
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.010140000000000281, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.010140000000000017,
estimated_gradient evaluates to -0.020280000000000298, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,35; feat = 0.50349999999999995; objective+ = 0.54626033299999999; objective- = 0.54666593299999999
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.017400000000001491, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.017400000000000006,
estimated_gradient evaluates to 0.034800000000001496, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,37; feat = 0.49239999999999995; objective+ = 0.54680113299999999; objective- = 0.54610513299999996
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.018260000000000998, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.018259999999999998,
estimated_gradient evaluates to -0.036520000000000996, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,38; feat = 0.3246; objective+ = 0.54608793299999991; objective- = 0.54681833299999993
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.015699999999998097, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.015699999999999999,
estimated_gradient evaluates to -0.031399999999998096, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,39; feat = 0.0118; objective+ = 0.54614913300000001; objective- = 0.54677713299999997
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.043299999999997792, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.043299999999999998,
estimated_gradient evaluates to 0.08659999999999779, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,40; feat = 0.4919; objective+ = 0.54732913299999997; objective- = 0.54559713300000001
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.050120000000001434, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.050120000000000005,
estimated_gradient evaluates to -0.10024000000000144, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,42; feat = 0.3805; objective+ = 0.54546073299999998; objective- = 0.547465533
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.10880000000000112, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.10880000000000001,
estimated_gradient evaluates to 0.21760000000000113, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,43; feat = 0.45029999999999998; objective+ = 0.548639133; objective- = 0.54428713299999998
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.011100000000005546, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.011100000000000002,
estimated_gradient evaluates to -0.022200000000005549, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,44; feat = 0.021999999999999999; objective+ = 0.54624113299999988; objective- = 0.54668513299999999
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.013309999999999421, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.013310000000000001,
estimated_gradient evaluates to 0.026619999999999422, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,45; feat = 0.66500000000000004; objective+ = 0.54670933300000002; objective- = 0.54617693300000003
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.067710000000002768, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.067709999999999992,
estimated_gradient evaluates to 0.13542000000000276, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,46; feat = 0.78159999999999996; objective+ = 0.547797333; objective- = 0.54508893299999994
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.021540000000000895, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.02154,
estimated_gradient evaluates to 0.043080000000000895, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,48; feat = 0.51739999999999997; objective+ = 0.54687393299999998; objective- = 0.54601233299999996
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.039320000000002034, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.039320000000000008,
estimated_gradient evaluates to -0.078640000000002042, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,50; feat = 0.37669999999999998; objective+ = 0.54565673299999995; objective- = 0.54722953299999999
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.038099999999998482, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.038100000000000009,
estimated_gradient evaluates to 0.076199999999998491, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,51; feat = 0.68300000000000005; objective+ = 0.54720513299999995; objective- = 0.54568113299999998
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.041009999999999311, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.041010000000000005,
estimated_gradient evaluates to -0.082019999999999316, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,53; feat = 0.35980000000000001; objective+ = 0.54562293299999998; objective- = 0.54726333299999996
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.025740000000003739, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.025740000000000006,
estimated_gradient evaluates to -0.051480000000003745, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,54; feat = 0.17520000000000002; objective+ = 0.54595833299999996; objective- = 0.54698793300000004
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.038209999999999279, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.038209999999999987,
estimated_gradient evaluates to -0.076419999999999266, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,55; feat = 0.61470000000000002; objective+ = 0.54570893300000001; objective- = 0.54723733299999999
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.03879999999999989, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.038800000000000001,
estimated_gradient evaluates to 0.077599999999999891, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,57; feat = 0.9798; objective+ = 0.54721913300000002; objective- = 0.54566713300000003
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.021399999999998386, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.021400000000000009,
estimated_gradient evaluates to 0.042799999999998395, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,58; feat = 0.80400000000000005; objective+ = 0.54687113300000001; objective- = 0.54601513300000004
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.012090000000001421, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.012090000000000002,
estimated_gradient evaluates to -0.024180000000001423, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,0,59; feat = 0.73570000000000002; objective+ = 0.54620133299999996; objective- = 0.54668493299999998
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.056860000000000487, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.056860000000000001,
estimated_gradient evaluates to 0.11372000000000049, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,0; feat = 0.93210000000000004; objective+ = 0.54758033299999997; objective- = 0.54530593299999996
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.023700000000002983, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.023700000000000013,
estimated_gradient evaluates to 0.047400000000002995, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,1; feat = 0.76670000000000005; objective+ = 0.546917133; objective- = 0.54596913299999994
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.018459999999995844, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.018460000000000001,
estimated_gradient evaluates to 0.036919999999995845, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,4; feat = 0.13059999999999999; objective+ = 0.54682233299999994; objective- = 0.54608393300000002
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.0107199999999948, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.010719999999999997,
estimated_gradient evaluates to -0.021439999999994797, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,5; feat = 0.24590000000000004; objective+ = 0.54623873300000003; objective- = 0.54666753299999993
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.020580000000001195, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.020580000000000001,
estimated_gradient evaluates to -0.041160000000001196, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,6; feat = 0.21940000000000004; objective+ = 0.54603153299999996; objective- = 0.54685473299999998
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.028059999999998392, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.028060000000000002,
estimated_gradient evaluates to -0.056119999999998393, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,7; feat = 0.36059999999999998; objective+ = 0.54588193299999999; objective- = 0.54700433299999995
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.039140000000002784, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.039140000000000008,
estimated_gradient evaluates to 0.078280000000002792, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,8; feat = 0.99560000000000004; objective+ = 0.547225933; objective- = 0.54566033299999994
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.017319999999996893, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.017320000000000002,
estimated_gradient evaluates to 0.034639999999996895, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,9; feat = 0.48770000000000002; objective+ = 0.54679953299999995; objective- = 0.54610673300000001
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.036579999999994332, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.036580000000000008,
estimated_gradient evaluates to -0.073159999999994341, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,11; feat = 0.16920000000000002; objective+ = 0.54572153300000004; objective- = 0.54718473299999992
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.063270000000002768, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.063269999999999993,
estimated_gradient evaluates to 0.12654000000000276, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,12; feat = 0.52929999999999999; objective+ = 0.54773853299999997; objective- = 0.54520773299999992
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.012947699999999476, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.019709999999999981,
estimated_gradient evaluates to -0.032657699999999457, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,13; feat = 0.49129999999999996; objective+ = 0.54607893299999999; objective- = 0.54673208699999998
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.021839999999995953, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.021839999999999991,
estimated_gradient evaluates to 0.043679999999995944, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,14; feat = 0.36159999999999998; objective+ = 0.5469099329999999; objective- = 0.54603633299999998
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.029380000000002141, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.029380000000000003,
estimated_gradient evaluates to 0.058760000000002144, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,15; feat = 0.6573; objective+ = 0.54703073299999994; objective- = 0.54585553299999989
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.047569999999999113, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.047570000000000001,
estimated_gradient evaluates to -0.095139999999999114, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,18; feat = 0.040000000000000001; objective+ = 0.545511733; objective- = 0.54741453299999998
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.080530000000001753, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.080530000000000004,
estimated_gradient evaluates to -0.16106000000000176, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,19; feat = 0.37159999999999999; objective+ = 0.54485253300000003; objective- = 0.54807373300000006
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.057540000000000736, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.057540000000000001,
estimated_gradient evaluates to 0.11508000000000074, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,20; feat = 0.42070000000000002; objective+ = 0.54761393299999994; objective- = 0.54531233299999993
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.018409999999992974, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.018409999999999996,
estimated_gradient evaluates to -0.036819999999992969, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,21; feat = 0.67530000000000001; objective+ = 0.546094933; objective- = 0.54683133299999986
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.01289000000000301, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.012890000000000013,
estimated_gradient evaluates to 0.025780000000003023, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,23; feat = 0.86770000000000003; objective+ = 0.54672093300000002; objective- = 0.54620533299999996
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.061780000000000342, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.061779999999999995,
estimated_gradient evaluates to 0.12356000000000034, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,24; feat = 0.98129999999999995; objective+ = 0.54767873299999992; objective- = 0.54520753299999991
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.020030000000002865, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.020030000000000006,
estimated_gradient evaluates to 0.040060000000002871, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,25; feat = 0.72999999999999998; objective+ = 0.546843733; objective- = 0.54604253299999994
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.073129999999998058, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.073130000000000001,
estimated_gradient evaluates to 0.14625999999999806, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,27; feat = 0.72160000000000002; objective+ = 0.54791573299999996; objective- = 0.544990533
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.011059999999997704, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.011059999999999993,
estimated_gradient evaluates to -0.022119999999997697, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,28; feat = 0.74570000000000003; objective+ = 0.54623193299999995; objective- = 0.5466743329999999
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.03866999999999797, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.038669999999999996,
estimated_gradient evaluates to -0.077339999999997966, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,29; feat = 0.44209999999999999; objective+ = 0.54567973299999994; objective- = 0.5472265329999999
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.046959999999997323, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.046960000000000016,
estimated_gradient evaluates to -0.093919999999997339, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,30; feat = 0.30199999999999999; objective+ = 0.54552393300000002; objective- = 0.54740233299999996
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.03425999999999968, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.034260000000000013,
estimated_gradient evaluates to 0.068519999999999692, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,31; feat = 0.93610000000000004; objective+ = 0.54714833299999999; objective- = 0.54577793299999999
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.073090000000001293, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.073090000000000016,
estimated_gradient evaluates to 0.14618000000000131, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,32; feat = 0.76990000000000003; objective+ = 0.547924933; objective- = 0.54500133299999998
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.016970000000004516, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.016970000000000006,
estimated_gradient evaluates to 0.033940000000004522, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,33; feat = 0.53190000000000004; objective+ = 0.54680253300000004; objective- = 0.54612373299999994
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.1368700000000001, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.13686999999999999,
estimated_gradient evaluates to -0.27374000000000009, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,34; feat = 0.10449999999999998; objective+ = 0.54372573299999993; objective- = 0.54920053299999994
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.023869999999996103, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.023870000000000016,
estimated_gradient evaluates to -0.047739999999996119, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,37; feat = 0.58999999999999997; objective+ = 0.54597573300000002; objective- = 0.54693053299999994
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.013520000000000396, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.013520000000000001,
estimated_gradient evaluates to 0.027040000000000397, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,38; feat = 0.85660000000000003; objective+ = 0.54672353299999998; objective- = 0.54618273299999998
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.052799999999994594, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.052799999999999993,
estimated_gradient evaluates to 0.10559999999999459, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,39; feat = 0.54469999999999996; objective+ = 0.54750913299999993; objective- = 0.54539713300000003
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.011499999999995247, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.0115,
estimated_gradient evaluates to -0.022999999999995246, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,40; feat = 0.0097999999999999979; objective+ = 0.54622313300000003; objective- = 0.54668313299999993
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.060530000000000611, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.06053,
estimated_gradient evaluates to 0.12106000000000061, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,42; feat = 0.88600000000000001; objective+ = 0.54765373299999998; objective- = 0.54523253299999996
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.012840000000000139, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.012840000000000008,
estimated_gradient evaluates to 0.025680000000000147, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,44; feat = 0.63190000000000002; objective+ = 0.54669993299999997; objective- = 0.54618633299999997
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.028600000000001694, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.0286,
estimated_gradient evaluates to -0.057200000000001694, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,45; feat = 0.032199999999999999; objective+ = 0.54588113299999996; objective- = 0.547025133
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.018479999999996999, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.018479999999999996,
estimated_gradient evaluates to -0.036959999999996995, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,49; feat = 0.39950000000000002; objective+ = 0.54608353300000001; objective- = 0.54682273299999995
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.021360000000001642, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.021360000000000004,
estimated_gradient evaluates to -0.042720000000001646, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,50; feat = 0.60970000000000002; objective+ = 0.54602593300000002; objective- = 0.54688033300000005
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.014839999999998594, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.014840000000000002,
estimated_gradient evaluates to -0.029679999999998596, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,51; feat = 0.13690000000000002; objective+ = 0.54616633299999995; objective- = 0.54675993299999992
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.012720000000004349, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.012719999999999999,
estimated_gradient evaluates to 0.025440000000004348, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,53; feat = 0.41589999999999999; objective+ = 0.54671753300000003; objective- = 0.54620873299999995
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.011780000000000249, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.011779999999999999,
estimated_gradient evaluates to 0.023560000000000247, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,54; feat = 0.12959999999999999; objective+ = 0.54667873299999992; objective- = 0.54620753299999991
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.024820000000000793, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.024820000000000002,
estimated_gradient evaluates to -0.049640000000000795, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,55; feat = 0.2437; objective+ = 0.54594673299999996; objective- = 0.54693953299999998
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.020280000000000596, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.020279999999999999,
estimated_gradient evaluates to 0.040560000000000596, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,56; feat = 0.91930000000000001; objective+ = 0.54684873299999992; objective- = 0.54603753299999991
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.01984000000000305, which exceeds threshold_ * scale, where
computed_gradient evaluates to 0.019839999999999997,
estimated_gradient evaluates to 0.039680000000003046, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,57; feat = 0.57889999999999997; objective+ = 0.546839933; objective- = 0.54604633299999994
./include/caffe/test/test_gradient_check_util.hpp:175: Failure
The difference between computed_gradient and estimated_gradient is 0.039639999999998239, which exceeds threshold_ * scale, where
computed_gradient evaluates to -0.039640000000000002,
estimated_gradient evaluates to -0.079279999999998241, and
threshold_ * scale evaluates to 0.01.
debug: (top_id, top_data_id, blob_id, feat_id)=0,0,1,58; feat = 0.053899999999999997; objective+ = 0.54565033299999999; objective- = 0.54723593299999995
Most of the values are doubled, because of the following statement in test_gradient_check_util.hpp
:
const Dtype loss_weight = 2; // I don't know why the value is 2.
loss = top[top_id]->cpu_data()[top_data_id] * loss_weight;
top[top_id]->mutable_cpu_diff()[top_data_id] = loss_weight;
Besides, in the Caffe layer, the top[0]->cpu_diff()[0]
also returns 2.
If I change doubled the loss values, there still be some mismatched values with the estimated_gradient
.
Could you tell me the reason?
Issue summary
The estimated gradients by
GradientChecker
are not correct. I implemented my own Caffe layer and the gradients are the same as PyTorch and JAX. ButGradientChecker
tells me that my gradient are not correct.Steps to reproduce
make -j8
make runtest GTEST_FILTER='Chamfer*' -j8
Tried solutions
Compare my gradients with autograd and PyTorch. And they are the same.
System configuration
Issue checklist