I need to implement a custom layer called upsample layer,which in prototxt is like this:
layer {
bottom: "layer97-conv"
top: "layer98-upsample"
name: "layer98-upsample"
type: "Upsample"
upsample_param {
scale: 2
}
As you can see,it has an upsample_param which contains its stride parameter,and I have written its IPlugin like this:
class UpsampleLayer : public IPlugin
{
public:
UpsampleLayer(){}
UpsampleLayer(size_t stride):stride_(stride)
{
std::cout<<"UpsampleLayer0"<<std::endl;
}
UpsampleLayer(const void* buffer,size_t sz, size_t stride):stride_(stride)
{
const int* d = reinterpret_cast<const int*>(buffer);
channel_=d[0];
w_=d[1];
h_=d[2];
std::cout<<"UpsampleLayer1"<<std::endl;
}
inline int getNbOutputs() const override { return 1; };
Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) override
{
std::cout<<"channel"<<inputs[0].d[0]<<"h:"<<inputs[0].d[1]<<"w:"<<inputs[0].d[2]<<std::endl;
channel_=inputs[0].d[0];
w_=inputs[0].d[1];
h_=inputs[0].d[2];
return DimsCHW(inputs[0].d[0], inputs[0].d[1]*stride_, inputs[0].d[2]*stride_);
}
int initialize() override
{
return 0;
}
inline void terminate() override
{
}
inline size_t getWorkspaceSize(int) const override { return 0; }
int enqueue(int batchSize, const void*const *inputs, void** outputs, void*, cudaStream_t stream) override
{
Forward_gpu((float*)inputs[0],1,channel_, w_, h_, stride_, (float*)outputs[0] );//this function is defined in upsamplelayer.cu
return 0;
}
size_t getSerializationSize() override
{
return 4*sizeof(int);
}
void serialize(void* buffer) override
{
int* d = reinterpret_cast<int*>(buffer);
d[0] = channel_; d[1] = w_; d[2] = h_;
d[3]=stride_;
}
void configure(const Dims*inputs, int nbInputs, const Dims* outputs, int nbOutputs, int) override
{
// dimBottom = DimsCHW(inputs[0].d[0], inputs[0].d[1], inputs[0].d[2]);
channel_=inputs[0].d[0];
w_=inputs[0].d[1];
h_=inputs[0].d[2];
}
protected:
int stride_;
int channel_;
int w_;
int h_;
};
But when I begin to run my code ,it shows
[libprotobuf ERROR google/protobuf/text_format.cc:298] Error parsing text-format ditcaffe.NetParameter: 2622:20:Message type "ditcaffe.LayerParameter" has no field named "upsample_param".
Could not parse deploy file
Segmentation fault (core dumped)
I’m new to tensorRT so I wonder how to define plugin layer with param so that it can be parsed by NVcaffeparser.
Any suggestions will be appreciated!Wish you a happy day!