mirror of
https://github.com/opencv/opencv.git
synced 2025-06-13 04:52:53 +08:00
Reset OpenCL kernels if batch size changes
This commit is contained in:
parent
0a61ebdd66
commit
0f01b40dd5
@ -273,6 +273,9 @@ public:
|
|||||||
for(int i = 0; i < outCn; i++ )
|
for(int i = 0; i < outCn; i++ )
|
||||||
biasvec[i] = biasMat.at<float>(i);
|
biasvec[i] = biasMat.at<float>(i);
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_OPENCL
|
||||||
|
convolutionOp.release();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool setActivation(const Ptr<ActivationLayer>& layer)
|
bool setActivation(const Ptr<ActivationLayer>& layer)
|
||||||
|
@ -267,6 +267,11 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifdef HAVE_OPENCL
|
#ifdef HAVE_OPENCL
|
||||||
|
void finalize(const std::vector<Mat*> &inputs, std::vector<Mat> &outputs)
|
||||||
|
{
|
||||||
|
innerProductOp.release();
|
||||||
|
}
|
||||||
|
|
||||||
bool forward_ocl(InputArrayOfArrays inps, OutputArrayOfArrays outs, InputArrayOfArrays internals)
|
bool forward_ocl(InputArrayOfArrays inps, OutputArrayOfArrays outs, InputArrayOfArrays internals)
|
||||||
{
|
{
|
||||||
std::vector<UMat> inputs;
|
std::vector<UMat> inputs;
|
||||||
|
@ -96,6 +96,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_OPENCL
|
#ifdef HAVE_OPENCL
|
||||||
|
void finalize(const std::vector<Mat*> &inputs, std::vector<Mat> &outputs)
|
||||||
|
{
|
||||||
|
lrnOp.release();
|
||||||
|
}
|
||||||
|
|
||||||
bool forward_ocl(InputArrayOfArrays inps, OutputArrayOfArrays outs, OutputArrayOfArrays internals)
|
bool forward_ocl(InputArrayOfArrays inps, OutputArrayOfArrays outs, OutputArrayOfArrays internals)
|
||||||
{
|
{
|
||||||
std::vector<UMat> inputs;
|
std::vector<UMat> inputs;
|
||||||
|
@ -126,6 +126,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
getConvPoolPaddings(inp, out, kernel, stride, padMode, Size(1, 1), pad);
|
getConvPoolPaddings(inp, out, kernel, stride, padMode, Size(1, 1), pad);
|
||||||
|
|
||||||
|
#ifdef HAVE_OPENCL
|
||||||
|
poolOp.release();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool supportBackend(int backendId)
|
virtual bool supportBackend(int backendId)
|
||||||
|
@ -95,14 +95,7 @@ public:
|
|||||||
#ifdef HAVE_OPENCL
|
#ifdef HAVE_OPENCL
|
||||||
virtual void finalize(const std::vector<Mat*> &inputs, std::vector<Mat> &outputs)
|
virtual void finalize(const std::vector<Mat*> &inputs, std::vector<Mat> &outputs)
|
||||||
{
|
{
|
||||||
OCL4DNNSoftmaxConfig config;
|
softmaxOp.release();
|
||||||
|
|
||||||
config.in_shape = shape(*inputs[0]);
|
|
||||||
config.axis = axisRaw;
|
|
||||||
config.channels = inputs[0]->size[axisRaw];
|
|
||||||
config.logsoftmax = logSoftMax;
|
|
||||||
|
|
||||||
softmaxOp = Ptr<OCL4DNNSoftmax<float> >(new OCL4DNNSoftmax<float>(config));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool forward_ocl(InputArrayOfArrays inps, OutputArrayOfArrays outs, OutputArrayOfArrays itns)
|
bool forward_ocl(InputArrayOfArrays inps, OutputArrayOfArrays outs, OutputArrayOfArrays itns)
|
||||||
@ -115,6 +108,18 @@ public:
|
|||||||
outs.getUMatVector(outputs);
|
outs.getUMatVector(outputs);
|
||||||
itns.getUMatVector(internals);
|
itns.getUMatVector(internals);
|
||||||
|
|
||||||
|
if (softmaxOp.empty())
|
||||||
|
{
|
||||||
|
OCL4DNNSoftmaxConfig config;
|
||||||
|
|
||||||
|
config.in_shape = shape(inputs[0]);
|
||||||
|
config.axis = axisRaw;
|
||||||
|
config.channels = inputs[0].size[axisRaw];
|
||||||
|
config.logsoftmax = logSoftMax;
|
||||||
|
|
||||||
|
softmaxOp = Ptr<OCL4DNNSoftmax<float> >(new OCL4DNNSoftmax<float>(config));
|
||||||
|
}
|
||||||
|
|
||||||
UMat& src = inputs[0];
|
UMat& src = inputs[0];
|
||||||
UMat& dstMat = outputs[0];
|
UMat& dstMat = outputs[0];
|
||||||
|
|
||||||
|
@ -77,6 +77,10 @@ OCL_TEST(Reproducibility_GoogLeNet, Accuracy)
|
|||||||
net.setPreferableBackend(DNN_BACKEND_DEFAULT);
|
net.setPreferableBackend(DNN_BACKEND_DEFAULT);
|
||||||
net.setPreferableTarget(DNN_TARGET_OPENCL);
|
net.setPreferableTarget(DNN_TARGET_OPENCL);
|
||||||
|
|
||||||
|
// Initialize network for a single image in the batch but test with batch size=2.
|
||||||
|
net.setInput(blobFromImage(Mat(224, 224, CV_8UC3)));
|
||||||
|
net.forward();
|
||||||
|
|
||||||
std::vector<Mat> inpMats;
|
std::vector<Mat> inpMats;
|
||||||
inpMats.push_back( imread(_tf("googlenet_0.png")) );
|
inpMats.push_back( imread(_tf("googlenet_0.png")) );
|
||||||
inpMats.push_back( imread(_tf("googlenet_1.png")) );
|
inpMats.push_back( imread(_tf("googlenet_1.png")) );
|
||||||
|
Loading…
Reference in New Issue
Block a user