mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Clip kernel for OpenCL PriorBox layer
This commit is contained in:
@@ -369,15 +369,11 @@ public:
|
||||
// clip the prior's coordinate such that it is within [0, 1]
|
||||
if (_clip)
|
||||
{
|
||||
Mat mat = outputs[0].getMat(ACCESS_READ);
|
||||
int aspect_count = (_maxSize > 0) ? 1 : 0;
|
||||
int offset = nthreads * 4 * _offsetsX.size() * (1 + aspect_count + _aspectRatios.size());
|
||||
float* outputPtr = mat.ptr<float>() + offset;
|
||||
int _outChannelSize = _layerHeight * _layerWidth * _numPriors * 4;
|
||||
for (size_t d = 0; d < _outChannelSize; ++d)
|
||||
{
|
||||
outputPtr[d] = std::min<float>(std::max<float>(outputPtr[d], 0.), 1.);
|
||||
}
|
||||
ocl::Kernel kernel("clip", ocl::dnn::prior_box_oclsrc, opts);
|
||||
size_t nthreads = _layerHeight * _layerWidth * _numPriors * 4;
|
||||
if (!kernel.args((int)nthreads, ocl::KernelArg::PtrReadWrite(outputs[0]))
|
||||
.run(1, &nthreads, NULL, false))
|
||||
return false;
|
||||
}
|
||||
|
||||
// set the variance.
|
||||
|
||||
@@ -107,3 +107,13 @@ __kernel void set_variance(const int nthreads,
|
||||
vstore4(var_vec, 0, dst + offset + index * 4);
|
||||
}
|
||||
}
|
||||
|
||||
__kernel void clip(const int nthreads,
|
||||
__global Dtype* dst)
|
||||
{
|
||||
for (int index = get_global_id(0); index < nthreads; index += get_global_size(0))
|
||||
{
|
||||
Dtype4 vec = vload4(index, dst);
|
||||
vstore4(clamp(vec, 0, 1), index, dst);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user