Nvidia Jetson Tx2 使用 VGG_VOC0712_SSD_300x300 模型(四)

5 篇文章 0 订阅
4 篇文章 0 订阅

ReshapeLayer.h

#ifndef __RESHAPE_LAYER_H__
#define __RESHAPE_LAYER_H__
#include <cassert>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cuda_runtime.h> 
#include "NvCaffeParser.h"
#include "NvInferPlugin.h"
#include "Common.h"

using namespace nvinfer1;
using namespace nvcaffeparser1;
using namespace plugin;

template<int OutC>
class ReshapeLayer: public IPlugin
{
public:
  ReshapeLayer()
  {
  }
  ReshapeLayer(const void* buffer, size_t size)
  {
    assert(size == sizeof(mCopySize));
    mCopySize = *reinterpret_cast<const size_t*>(buffer);
  }

  int getNbOutputs() const override
  {
    return 1;
  }
  Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) override
  {
#ifdef DEBUG
    return DimsCHW(inputs[0].d[0], inputs[0].d[1], inputs[0].d[2]);
#else
    assert(nbInputDims == 1);
    assert(index == 0);
    assert(inputs[index].nbDims == 3);
    assert((inputs[0].d[0]) * (inputs[0].d[1]) % OutC == 0);
    return DimsCHW(OutC, inputs[0].d[0] * inputs[0].d[1] / OutC, inputs[0].d[2]);
#endif
  }

  int initialize() override
  {
    return 0;
  }

  void terminate() override
  {
  }

  size_t getWorkspaceSize(int) const override
  {
    return 0;
  }

  // currently it is not possible for a plugin to execute "in place". Therefore we memcpy the data from the input to the output buffer
  int enqueue(int batchSize, const void* const *inputs, void** outputs, void*, cudaStream_t stream) override
  {
    CHECK(cudaMemcpyAsync(outputs[0], inputs[0], mCopySize * batchSize, cudaMemcpyDeviceToDevice, stream));
    return 0;
  }

  size_t getSerializationSize() override
  {
    return sizeof(mCopySize);
  }

  void serialize(void* buffer) override
  {
    *reinterpret_cast<size_t*>(buffer) = mCopySize;
  }

  void configure(const Dims*inputs, int nbInputs, const Dims* outputs, int nbOutputs, int) override
  {
    mCopySize = inputs[0].d[0] * inputs[0].d[1] * inputs[0].d[2] * sizeof(float);
  }

protected:
  size_t mCopySize;
};
#endif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值