You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "cropLayer.h"
  2. #define LOG( X ) m_pLog->Log( "CropL", this, X )
  3. #define LOG_ERROR( X ) m_pLog->Log( "CropL", this, _LOG_ERROR, X )
  4. cropLayer::cropLayer(bool useGPU) :cortexLayer(CROP, useGPU){
  5. m_fScale = 1.f;
  6. m_bFlipped = false;
  7. m_fAngle = 0.f;
  8. m_fSaturation = 1.f;
  9. m_fExposure = 1.f;
  10. m_pGpuRand = NULL;
  11. };
  12. cropLayer::~cropLayer(){
  13. if (m_pGpuRand != NULL) m_pPU->freeMem(m_pGpuRand);
  14. };
  15. bool cropLayer::create(uint32_t batch, uint32_t h, uint32_t w, uint32_t c, uint32_t crop_height, uint32_t crop_width, bool flip, float angle, float saturation, float exposure){
  16. char tBuff[256];
  17. sprintf(tBuff, "Crop Layer: %d x %d -> %d x %d x %d image\n", h, w, crop_height, crop_width, c);
  18. LOG(tBuff);
  19. m_nBatch = batch;
  20. m_nIn_Height = h;
  21. m_nIn_Width = w;
  22. m_nIn_Channels = c;
  23. m_fScale = (float)crop_height / h;
  24. m_bFlipped = flip;
  25. m_fAngle = angle;
  26. m_fSaturation = saturation;
  27. m_fExposure = exposure;
  28. m_nOut_Width = crop_width;
  29. m_nOut_Height = crop_height;
  30. m_nOut_Channels = c;
  31. m_nInput = m_nIn_Width * m_nIn_Height * m_nIn_Channels;
  32. m_nOutput = m_nOut_Width * m_nOut_Height * m_nOut_Channels;
  33. m_nOutputVol = m_nOutput * m_nBatch;
  34. m_pOutput = (float*)calloc(m_nOutputVol, sizeof(float));
  35. if (m_pOutput == NULL)return false;
  36. #ifdef GPU
  37. if (m_bUseGPU){
  38. m_pGpuOutput = m_pPU->makeFloatArray(m_nOutputVol);
  39. if (m_pGpuOutput = NULL){
  40. free(m_pOutput); m_pOutput = NULL;
  41. return false;
  42. };
  43. m_pGpuRand = m_pPU->makeFloatArray(m_nBatch*8);
  44. if (m_pGpuRand = NULL){
  45. free(m_pOutput); m_pOutput = NULL;
  46. m_pPU->freeMem(m_pGpuOutput); m_pGpuOutput = NULL;
  47. return false;
  48. };
  49. };
  50. #endif
  51. return true;
  52. };
  53. #undef LOG
  54. #undef LOG_ERROR