Newer
Older
SparseCodingDynamicOcclusions / paramFiles / trainingParams.lua
@Hvitgar Hvitgar on 22 Sep 2016 15 KB Code, Data and Thesis added
package.path = package.path .. ";" .. "/home/neuralnetlab/workspace/OpenPV/parameterWrapper/?.lua"; -- needs to be adjusted
local pv = require "PVModule";
--local subnets = require "PVSubnets";

local nbatch           = 32;    --Batch size of learning
local nxSize           = 64;    --Cifar is 32 x 32
local nySize           = 16;
local xpatchSize       = nxSize;
local ypatchSize       = nySize;
local displayPeriod    = 100;   --Number of timesteps to find sparse approximation
local numEpochs        = 3;     --Number of times to run through dataset
local numImages        = 100000; --Total number of images in dataset
local stopTime         = math.ceil((numImages  * numEpochs) / nbatch) * displayPeriod;
local writeStep        = displayPeriod*100; 
local initialWriteTime = displayPeriod; 

local inputPath        = ; --path to a .txt file with all paths to input images
local outputPath       = "output/";
local checkpointPeriod = (displayPeriod * 1000); -- How often to write checkpoints

local numBasisVectors  = 512;  --1024; --2048; --depending on how many basis functions were trained
local basisVectorFile  = nil;   --nil for initial weights, otherwise, specifies the weights file to load. Change init parameter in MomentumConn
local plasticityFlag   = true;  --Determines if we are learning weights or holding them constant
local momentumTau      = 50;   --The momentum parameter. A single weight update will last for momentumTau timesteps.
local dWMax            = 0.01; -- 0.05; -- 0.10;    --The learning rate
local VThresh          = .035;  --.05; --.065; --The threshold, or lambda, of the network
local AMin             = 0;
local AMax             = infinity;
local AShift           = VThresh;  --This being equal to VThresh is a soft threshold
local VWidth           = 0; 
local timeConstantTau  = math.ceil(displayPeriod/15);   --The integration tau for sparse approximation
local weightInit       = math.sqrt((1/xpatchSize)*(1/ypatchSize)*(1/3));

-- Base table variable to store
local pvParameters = {

   --Layers------------------------------------------------------------
   --------------------------------------------------------------------   
   column = {
      groupType = "HyPerCol";
      startTime                           = 0;
      dt                                  = 1;
      dtAdaptFlag                         = true;
      useAdaptMethodExp1stOrder           = true;
      dtAdaptController                   = "V1EnergyProbe";
      dtAdaptTriggerLayerName             = "Input";
      dtAdaptTriggerOffset                = 0;
      dtScaleMax                          = 1; --1.0; -- minimum value for the maximum time scale, regardless of tau_eff
      dtScaleMin                          = 0.1; -- default time scale to use after image flips or when something is wacky
      dtChangeMax                         = 0.1; -- determines fraction of tau_effective to which to set the time step, can be a small percentage as tau_eff can be huge
      dtChangeMin                         = 0.05; -- percentage increase in the maximum allowed time scale whenever the time scale equals the current maximum
      dtMinToleratedTimeScale             = 0.0001;
      stopTime                            = stopTime;
      progressInterval                    = (displayPeriod * 10);
      writeProgressToErr                  = true;
      verifyWrites                        = false;
      outputPath                          = outputPath;
      printParamsFilename                 = "occlusion.params";
      randomSeed                          = 1234567890;
      nx                                  = nxSize;
      ny                                  = nySize;
      nbatch                              = nbatch;
      filenamesContainLayerNames          = 2;
      filenamesContainConnectionNames     = 2;
      initializeFromCheckpointDir         = "";
      defaultInitializeFromCheckpointFlag = false;
      checkpointWrite                     = true;
      checkpointWriteDir                  = outputPath .. "/Checkpoints"; --The checkpoint output directory
      checkpointWriteTriggerMode          = "step";
      checkpointWriteStepInterval         = checkpointPeriod; --How often to checkpoint
      deleteOlderCheckpoints              = false;
      suppressNonplasticCheckpoints       = false;
      writeTimescales                     = true;
      errorOnNotANumber                   = false;
   };

   Input = {
      groupType = "Movie";
      nxScale                             = 1;
      nyScale                             = 1;
      nf                                  = 1;
      phase                               = 0;
      mirrorBCflag                        = true;
      initializeFromCheckpointFlag        = false;
      writeStep                           = writeStep;
      initialWriteTime                    = initialWriteTime;
      sparseLayer                         = false;
      updateGpu                           = false;
      dataType                            = nil;
      inputPath                           = inputPath;
      offsetAnchor                        = "tl";
      offsetX                             = 0;
      offsetY                             = 0;
      writeImages                         = 0;
      inverseFlag                         = false;
      normalizeLuminanceFlag              = true;
      normalizeStdDev                     = true;
      jitterFlag                          = 0;
      useImageBCflag                      = false;
      padValue                            = 0;
      autoResizeFlag                      = false;
      displayPeriod                       = displayPeriod;
      echoFramePathnameFlag               = true;
      batchMethod                         = "byImage";
      start_frame_index                   = {0.000000};
      writeFrameToTimestamp               = true;
      flipOnTimescaleError                = true;
      resetToStartOnLoop                  = false;
   };

   InputError = {
      groupType = "ANNLayer";
      nxScale                             = 1;
      nyScale                             = 1;
      nf                                  = 1;
      phase                               = 1;
      mirrorBCflag                        = false;
      valueBC                             = 0;
      initializeFromCheckpointFlag        = false;
      InitVType                           = "ZeroV";
      triggerLayerName                    = NULL;
      writeStep                           = displayPeriod;
      initialWriteTime                    = initialWriteTime;
      sparseLayer                         = false;
      updateGpu                           = false;
      dataType                            = nil;
      VThresh                             = -infinity;
      AMin                                = -infinity;
      AMax                                = infinity;
      AShift                              = 0;
      clearGSynInterval                   = 0;
      useMask                             = false;
   };

   V1 = {
      groupType = "HyPerLCALayer";
      nxScale                             = 1/nxSize;
      nyScale                             = 1/nySize;
      nf                                  = numBasisVectors;
      phase                               = 2;
      mirrorBCflag                        = false;
      valueBC                             = 0;
      initializeFromCheckpointFlag        = false;
      InitVType                           = "ConstantV";
      valueV                              = VThresh;
      --InitVType                           = "InitVFromFile";
      --Vfilename                           = "V1_V.pvp";
      triggerLayerName                    = NULL;
      writeStep                           = displayPeriod;
      initialWriteTime                    = initialWriteTime;
      sparseLayer                         = true;
      writeSparseValues                   = true;
      updateGpu                           = true;
      dataType                            = nil;
      VThresh                             = VThresh;
      AMin                                = AMin;
      AMax                                = AMax;
      AShift                              = AShift;
      VWidth                              = VWidth;
      clearGSynInterval                   = 0;
      timeConstantTau                     = timeConstantTau;
      selfInteract                        = true;
   };

   InputRecon = {
      groupType = "ANNLayer";
      nxScale                             = 1;
      nyScale                             = 1;
      nf                                  = 1;
      phase                               = 3;
      mirrorBCflag                        = false;
      valueBC                             = 0;
      initializeFromCheckpointFlag        = false;
      InitVType                           = "ZeroV";
      triggerLayerName                    = NULL;
      writeStep                           = writeStep;
      initialWriteTime                    = initialWriteTime;
      sparseLayer                         = false;
      updateGpu                           = false;
      dataType                            = nil;
      VThresh                             = -infinity;
      AMin                                = -infinity;
      AMax                                =  infinity;
      AShift                              = 0;
      VWidth                              = 0;
      clearGSynInterval                   = 0;
   };

--Connections ------------------------------------------------------
--------------------------------------------------------------------

   InputToError = {
      groupType = "RescaleConn";
      preLayerName                        = "Input";
      postLayerName                       = "InputError";
      channelCode                         = 0;
      delay                               = {0.000000};
      scale                               = weightInit;
   };

   ErrorToV1 = {
      groupType = "TransposeConn";
      preLayerName                        = "InputError";
      postLayerName                       = "V1";
      channelCode                         = 0;
      delay                               = {0.000000};
      convertRateToSpikeCount             = false;
      receiveGpu                          = true;
      updateGSynFromPostPerspective       = true;
      pvpatchAccumulateType               = "convolve";
      writeStep                           = -1;
      writeCompressedCheckpoints          = false;
      selfFlag                            = false;
      gpuGroupIdx                         = -1;
      originalConnName                    = "V1ToError";
   };

   V1ToError = {
      groupType = "MomentumConn";
      preLayerName                        = "V1";
      postLayerName                       = "InputError";
      channelCode                         = -1;
      delay                               = {0.000000};
      numAxonalArbors                     = 1;
      plasticityFlag                      = plasticityFlag;
      convertRateToSpikeCount             = false;
      receiveGpu                          = false; -- non-sparse -> non-sparse
      sharedWeights                       = true;
      weightInitType                      = "UniformRandomWeight";
      wMinInit                            = -1;
      wMaxInit                            = 1;
      sparseFraction                      = 0.9;
      --weightInitType                      = "FileWeight";
      --initWeightsFile                     = basisVectorFile;
      useListOfArborFiles                 = false;
      combineWeightFiles                  = false;
      initializeFromCheckpointFlag        = false;
      triggerLayerName                    = "Input";
      triggerOffset                       = 0;
      updateGSynFromPostPerspective       = false; -- Should be false from V1 (sparse layer) to Error (not sparse). Otherwise every input from pre will be calculated (Instead of only active ones)
      pvpatchAccumulateType               = "convolve";
      writeStep                           = writeStep;
      initialWriteTime                    = initialWriteTime;
      writeCompressedCheckpoints          = false;
      selfFlag                            = false;
      nxp                                 = xpatchSize;
      nyp                                 = ypatchSize;
      shrinkPatches                       = false;
      normalizeMethod                     = "normalizeL2";
      strength                            = 1;
      normalizeArborsIndividually         = false;
      normalizeOnInitialize               = true;
      normalizeOnWeightUpdate             = true;
      rMinX                               = 0;
      rMinY                               = 0;
      nonnegativeConstraintFlag           = false;
      normalize_cutoff                    = 0;
      normalizeFromPostPerspective        = false;
      minL2NormTolerated                  = 0;
      dWMax                               = dWMax; 
      keepKernelsSynchronized             = true;
      useMask                             = false;
      momentumTau                         = momentumTau;   --The momentum parameter. A single weight update will last for momentumTau timesteps.
      momentumMethod                      = "viscosity";
      momentumDecay                       = 0;
   }; 

   V1ToRecon = {
      groupType = "CloneConn";
      preLayerName                        = "V1";
      postLayerName                       = "InputRecon";
      channelCode                         = 0;
      delay                               = {0.000000};
      convertRateToSpikeCount             = false;
      receiveGpu                          = false;
      updateGSynFromPostPerspective       = false;
      pvpatchAccumulateType               = "convolve";
      writeCompressedCheckpoints          = false;
      selfFlag                            = false;
      originalConnName                    = "V1ToError";
   };

   ReconToError = {
      groupType = "IdentConn";
      preLayerName                        = "InputRecon";
      postLayerName                       = "InputError";
      channelCode                         = 1;
      delay                               = {0.000000};
      initWeightsFile                     = nil;
   };

   --Probes------------------------------------------------------------
   --------------------------------------------------------------------

   V1EnergyProbe = {
      groupType = "ColumnEnergyProbe";
      message                             = nil;
      textOutputFlag                      = true;
      probeOutputFile                     = "V1EnergyProbe.txt";
      triggerLayerName                    = nil;
      energyProbe                         = nil;
   };

   InputErrorL2NormEnergyProbe = {
      groupType = "L2NormProbe";
      targetLayer                         = "InputError";
      message                             = nil;
      textOutputFlag                      = true;
      probeOutputFile                     = "InputErrorL2NormEnergyProbe.txt";
      energyProbe                         = "V1EnergyProbe";
      coefficient                         = 0.5;
      maskLayerName                       = nil;
      exponent                            = 2;
   };

   V1L1NormEnergyProbe = {
      groupType = "L1NormProbe";
      targetLayer                         = "V1";
      message                             = nil;
      textOutputFlag                      = true;
      probeOutputFile                     = "V1L1NormEnergyProbe.txt";
      energyProbe                         = "V1EnergyProbe";
      coefficient                         = 0.025;
      maskLayerName                       = nil;
   };

} --End of pvParameters

-- Print out PetaVision approved parameter file to the console
pv.printConsole(pvParameters)