PetaVision  Alpha
Segmentify.hpp
1 #ifndef SEGMENTIFY_HPP_
2 #define SEGMENTIFY_HPP_
3 
4 #include "HyPerLayer.hpp"
5 #include "SegmentLayer.hpp"
6 
7 namespace PV {
8 
9 class Segmentify : public PV::HyPerLayer {
10  public:
11  Segmentify(const char *name, HyPerCol *hc);
12  virtual Response::Status
13  communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) override;
14  virtual Response::Status allocateDataStructures() override;
15  virtual bool activityIsSpiking() override { return false; }
16  virtual ~Segmentify();
17 
18  protected:
19  Segmentify();
20  int initialize(const char *name, HyPerCol *hc);
21  int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override;
22  void ioParam_originalLayerName(enum ParamsIOFlag ioFlag);
23  void ioParam_segmentLayerName(enum ParamsIOFlag ioFlag);
24  // Defines the way to reduce values within a segment
25  // into a single scalar. Options are "average", "sum", and "max".
26  void ioParam_inputMethod(enum ParamsIOFlag ioFlag);
27  // Defines the way to fill the output segment with the
28  // reduced scalar method. Options are "centroid" and "fill"
29  void ioParam_outputMethod(enum ParamsIOFlag ioFlag);
30  virtual void allocateV() override;
31  virtual void initializeV() override;
32  virtual void initializeActivity() override;
33 
34  virtual Response::Status updateState(double timef, double dt) override;
35 
36  float calcNormDist(float xVal, float mean, float binSigma);
37 
38  private:
39  int initialize_base();
40 
41  protected:
42  int checkLabelValBuf(int newSize);
43  int buildLabelToIdx(int batchIdx);
44  int calculateLabelVals(int batchIdx);
45  int setOutputVals(int batchIdx);
46 
47  char *originalLayerName;
48  HyPerLayer *originalLayer;
49  char *segmentLayerName;
50  SegmentLayer *segmentLayer;
51 
52  // Reusing this buffer for batches
53  // Map to go from label to index into labelVals
54  std::map<int, int> labelToIdx;
55  // Matrix to store values (one dim for features, one for # labels
56  int numLabelVals;
57  int *labelIdxBuf;
58  float **labelVals;
59  int **labelCount;
60 
61  char *inputMethod;
62  char *outputMethod;
63 
64 }; // class Segmentify
65 
66 } /* namespace PV */
67 #endif
int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
Definition: Segmentify.cpp:34