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.

64 lines
1.7 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "costLayer.h"
  2. #define LOG( X ) m_pLog->Log( "COST", this, X )
  3. #define LOG_ERROR( X ) m_pLog->Log( "COST", this, _LOG_ERROR, X )
  4. costLayer::costLayer(bool useGPU) : cortexLayer(COST, useGPU){
  5. m_fScale = 1.f;
  6. m_eCostType = L1;
  7. };
  8. costLayer::~costLayer(){
  9. };
  10. bool costLayer::create(uint32_t batch, uint32_t inputs, COST_TYPE cost_type, float scale){
  11. char tBuff[256];
  12. sprintf(tBuff, "cost %4d\n", inputs);
  13. LOG(tBuff);
  14. m_fScale = scale;
  15. m_nBatch = batch;
  16. m_nInput = inputs;
  17. m_nDelta = m_nOutput = inputs;
  18. m_eCostType = cost_type;
  19. m_nDeltaVol = m_nOutputVol = m_nOutput * m_nBatch;
  20. m_pDelta = (float*)calloc(m_nDeltaVol, sizeof(float));
  21. m_pOutput = (float*)calloc(m_nOutputVol, sizeof(float));
  22. //l.cost = (float*)calloc(1, sizeof(float));
  23. #ifdef GPU
  24. if (m_bUseGPU){
  25. m_pGpuOutput = m_pPU->makeFloatArray(m_nOutputVol);
  26. if (m_pGpuOutput = NULL){
  27. free(m_pOutput); m_pOutput = NULL;
  28. free(m_pDelta); m_pDelta = NULL;
  29. return false;
  30. };
  31. m_pGpuDelta = m_pPU->makeFloatArray(m_nDeltaVol);
  32. if (m_pGpuDelta = NULL){
  33. free(m_pOutput); m_pOutput = NULL;
  34. free(m_pDelta); m_pDelta = NULL;
  35. m_pPU->freeMem(m_pGpuOutput); m_pGpuOutput = NULL;
  36. return false;
  37. };
  38. };
  39. #endif
  40. return true;
  41. };
  42. void costLayer::resizeEX(int inputs){
  43. m_nInput = inputs;
  44. m_nOutput = inputs;
  45. m_pDelta = (float*)realloc(m_pDelta, m_nDeltaVol * sizeof(float));
  46. m_pOutput = (float*)realloc(m_pOutput, m_nOutputVol * sizeof(float));
  47. #ifdef GPU
  48. m_pPU->freeMem( m_pGpuDelta );
  49. m_pPU->freeMem( m_pGpuOutput );
  50. m_pGpuDelta = m_pPU->makeFloatArray(m_nDeltaVol, m_pDelta);
  51. m_pGpuOutput = m_pPU->makeFloatArray(m_nOutputVol, m_pOutput);
  52. #endif
  53. }
  54. #undef LOG
  55. #undef LOG_ERROR