A little bit of cleanup

This commit is contained in:
Davis King 2020-04-18 09:30:59 -04:00
parent 55e9c890fd
commit 0e923cff93
2 changed files with 9 additions and 5 deletions

View File

@ -498,6 +498,8 @@ namespace dlib
mutable cuda_data_void_ptr buf;
};
// ----------------------------------------------------------------------------------------
class compute_loss_multiclass_log_per_pixel
{
/*!
@ -557,6 +559,8 @@ namespace dlib
mutable cuda_data_void_ptr buf;
};
// ----------------------------------------------------------------------------------------
class compute_loss_mean_squared_per_channel_and_pixel
{
/*!
@ -581,15 +585,15 @@ namespace dlib
) const
{
const auto image_size = subnetwork_output.nr()*subnetwork_output.nc()*subnetwork_output.k();
const size_t bytes_per_plane = image_size*sizeof(float);
const size_t bytes_per_image = image_size*sizeof(float);
// Allocate a cuda buffer to store all the truth images and also one float
// for the scalar loss output.
buf = device_global_buffer(subnetwork_output.num_samples()*bytes_per_plane + sizeof(float));
buf = device_global_buffer(subnetwork_output.num_samples()*bytes_per_image + sizeof(float));
cuda_data_ptr<float> loss_buf = static_pointer_cast<float>(buf, 1);
buf = buf+sizeof(float);
const size_t bytes_per_channel = subnetwork_output.nr()*subnetwork_output.nc()*sizeof(float);
const size_t bytes_per_plane = subnetwork_output.nr()*subnetwork_output.nc()*sizeof(float);
// copy the truth data into a cuda buffer.
for (long i = 0; i < subnetwork_output.num_samples(); ++i, ++truth)
@ -599,7 +603,7 @@ namespace dlib
for (size_t j = 0; j < t.size(); ++j) {
DLIB_ASSERT(t[j].nr() == subnetwork_output.nr());
DLIB_ASSERT(t[j].nc() == subnetwork_output.nc());
memcpy(buf + i*bytes_per_plane + j*bytes_per_channel, &t[j](0,0), bytes_per_channel);
memcpy(buf + i*bytes_per_image + j*bytes_per_plane, &t[j](0,0), bytes_per_plane);
}
}

View File

@ -2640,7 +2640,7 @@ namespace
tensor& grad = net.subnet().get_gradient_input();
cuda_compute(labels.begin(), output_tensor, grad, cuda_loss);
cpu_compute(labels.begin(), output_tensor, grad, cpu_loss);
const auto err = ::std::abs<double>(cuda_loss - cpu_loss) / cpu_loss;
const auto err = abs(cuda_loss - cpu_loss) / cpu_loss;
DLIB_TEST_MSG(err < 1e-6, "multi channel cuda and cpu losses differ");
#endif
}