コード例 #1
0
ファイル: main.cpp プロジェクト: dpaiton/OpenPV
int copyCorrectOutput(HyPerCol * hc, int argc, char * argv[]) {
   int status = PV_SUCCESS;
   std::string sourcePathString = hc->getOutputPath();
   sourcePathString += "/" "a3_reconstruction.pvp";
   const char * sourcePath = sourcePathString.c_str();
   MoviePvp * correctLayer = dynamic_cast<MoviePvp *>(hc->getLayerFromName("correct"));
   assert(correctLayer);
   const char * destPath = correctLayer->getInputPath();
   if (strcmp(&destPath[strlen(destPath)-4], ".pvp")!=0) {
      if (hc->columnId()==0) {
         fprintf(stderr, "%s --generate: This system test assumes that the layer \"correct\" is a Movie layer with imageListPath ending in \".pvp\".\n", argv[0]);
      }
      MPI_Barrier(hc->icCommunicator()->communicator());
      exit(EXIT_FAILURE);
   }
   if (hc->columnId()==0) {
      PV_Stream * infile = PV_fopen(sourcePath, "r", false/*verifyWrites*/);
      assert(infile);
      PV_fseek(infile, 0L, SEEK_END);
      long int filelength = PV_ftell(infile);
      PV_fseek(infile, 0L, SEEK_SET);
      char * buf = (char *) malloc((size_t) filelength);
      size_t charsread = PV_fread(buf, sizeof(char), (size_t) filelength, infile);
      assert(charsread == (size_t) filelength);
      PV_fclose(infile); infile = NULL;
      PV_Stream * outfile = PV_fopen(destPath, "w", false/*verifyWrites*/);
      assert(outfile);
      size_t charswritten = PV_fwrite(buf, sizeof(char), (size_t) filelength, outfile);
      assert(charswritten == (size_t) filelength);
      PV_fclose(outfile); outfile = NULL;
      free(buf); buf = NULL;
   }
   return status;
}
コード例 #2
0
ファイル: Movie.cpp プロジェクト: williamedwardhahn/OpenPV
/**
 * - Update the image buffers
 * - If the time is a multiple of biasChangetime then the position of the bias (biasX, biasY) changes.
 * - With probability persistenceProb the offset position (offsetX, offsetY) remains unchanged.
 * - Otherwise, with probability (1-persistenceProb) the offset position performs a random walk
 *   around the bias position (biasX, biasY).
 *
 * - If the time is a multiple of displayPeriod then load the next image.
 * - If nf=1 then the image is converted to grayscale during the call to read(filename, offsetX, offsetY).
 *   If nf>1 then the image is loaded with color information preserved.
 * - Return true if buffers have changed
 */
bool Movie::updateImage(double time, double dt)
{
   if( jitterFlag ) {
      jitter();
   } // jitterFlag

   InterColComm * icComm = getParent()->icCommunicator();

      //TODO: Fix movie layer to take with batches. This is commented out for compile
      //if(!flipOnTimescaleError && (parent->getTimeScale() > 0 && parent->getTimeScale() < parent->getTimeScaleMin())){
      //   if (parent->icCommunicator()->commRank()==0) {
      //      std::cout << "timeScale of " << parent->getTimeScale() << " is less than timeScaleMin of " << parent->getTimeScaleMin() << ", Movie is keeping the same frame\n";
      //   }
      //}
      //else{
         //Only do this if it's not the first update timestep
         //The timestep number is (time - startTime)/(width of timestep), with allowance for roundoff.
         //But if we're using adaptive timesteps, the dt passed as a function argument is not the correct (width of timestep).  
      if(fabs(time - (parent->getStartTime() + parent->getDeltaTime())) > (parent->getDeltaTime()/2)){
         int status = getFrame(time, dt);
         assert(status == PV_SUCCESS);
      }
      
      


      //nextDisplayTime removed, now using nextUpdateTime in HyPerLayer
      //while (time >= nextDisplayTime) {
      //   nextDisplayTime += displayPeriod;
      //}
      //Set frame number (member variable in Image)
      
      //Write to timestamp file here when updated
      if( icComm->commRank()==0 ) {
          //Only write if the parameter is set
          if(timestampFile){
             std::ostringstream outStrStream;
             outStrStream.precision(15);
             int kb0 = getLayerLoc()->kb0;
             for(int b = 0; b < parent->getNBatch(); b++){
                outStrStream << time << "," << b+kb0 << "," << frameNumbers[b] << "," << framePath[b] << "\n";
             }

             size_t len = outStrStream.str().length();
             int status = PV_fwrite(outStrStream.str().c_str(), sizeof(char), len, timestampFile)==len ? PV_SUCCESS : PV_FAILURE;
             if (status != PV_SUCCESS) {
                fprintf(stderr, "%s \"%s\" error: Movie::updateState failed to write to timestamp file.\n", getKeyword(), name);
                exit(EXIT_FAILURE);
             }
             //Flush buffer
             fflush(timestampFile->fp);
          }
      }
   //} // randomMovie

   return true;
}
コード例 #3
0
bool DisparityMovie::updateImage(double timef, double dt){
   InterColComm * icComm = getParent()->icCommunicator();
   assert(!readPvpFile);

   if(fabs(timef - (parent->getStartTime() + parent->getDeltaTime())) > (parent->getDeltaTime()/2)){
      //If disparity is over numDisparity, read new image and reset index
      if(disparityIndex >= numDisparity - 1){
         if (filename != NULL) free(filename);
         filename = strdup(getNextFileName(skipFrameIndex));
         disparityIndex = 0;
         frameCount++;
      }
      else{
         disparityIndex++;
      }
   }
   assert(filename != NULL);

   //Set frame number (member variable in Image)
   int newOffsetX;
   if((frameCount + frameOffset) % 2 == 0){
      newOffsetX = this->offsets[0];
   }
   else{
      newOffsetX = this->offsets[0] + (disparityIndex * dPixelDisparity);
   }
   int status = readImage(filename, newOffsetX, this->offsets[1], this->offsetAnchor);
   if( status != PV_SUCCESS ) {
      fprintf(stderr, "Movie %s: Error reading file \"%s\"\n", name, filename);
      abort();
   }
   //Write to timestamp file here when updated
   if( icComm->commRank()==0 ) {
      //Only write if the parameter is set
      if(timestampFile){
         std::ostringstream outStrStream;
         outStrStream.precision(15);
         outStrStream << frameNumber << "," << timef << "," << filename << "\n";
         size_t len = outStrStream.str().length();
         int status = PV_fwrite(outStrStream.str().c_str(), sizeof(char), len, timestampFile)==len ? PV_SUCCESS : PV_FAILURE;
         if (status != PV_SUCCESS) {
            fprintf(stderr, "%s \"%s\" error: Movie::updateState failed to write to timestamp file.\n", parent->parameters()->groupKeywordFromName(name), name);
            exit(EXIT_FAILURE);
         }
         //Flush buffer
         fflush(timestampFile->fp);
      }
   }
   return true;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: PetaVision/OpenPV
int generate(PV_Init* initObj, int rank) {
   // Remove -r and -c
   initObj->setRestartFlag(false);
   initObj->setCheckpointReadDir(NULL);
   if (rank==0) {
      pvInfo().printf("Running --generate with effective command line\n", initObj->getProgramName());
      initObj->printState();
   }
   if (rank==0) {
      PV_Stream * emptyinfile = PV_fopen("input/correct.pvp", "w", false/*verifyWrites*/);
      // Data for a CORRECT_PVP_NX-by-CORRECT_PVP_NY layer with CORRECT_PVP_NF features.
      // Sparse activity with no active neurons so file size doesn't change with number of features
      int emptydata[] = {80, 20, 2, CORRECT_PVP_NX, CORRECT_PVP_NY, CORRECT_PVP_NF, 1, 0, 4, 2, 1, 1, CORRECT_PVP_NX, CORRECT_PVP_NY, 0, 0, 0, 1, 0, 0, 0, 0, 0};
      size_t numwritten = PV_fwrite(emptydata, 23, sizeof(int), emptyinfile);
      if (numwritten != 23) {
         pvErrorNoExit().printf("%s failure to write placeholder data into input/correct.pvp file.\n", initObj->getProgramName());
      }
      PV_fclose(emptyinfile);
   }
   int status = rebuildandrun(initObj, NULL, &copyCorrectOutput, NULL, 0);
   return status;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: dpaiton/OpenPV
int generate(PV_Init* initObj, int rank) {
   PV_Arguments * arguments = initObj->getArguments();

   // Remove -r and -c
   arguments->setRestartFlag(false);
   arguments->setCheckpointReadDir(NULL);
   if (rank==0) {
      printf("%s --generate running PetaVision with arguments\n", arguments->getProgramName());
      arguments->printState();
   }
   if (rank==0) {
      PV_Stream * emptyinfile = PV_fopen("input/correct.pvp", "w", false/*verifyWrites*/);
      // Data for a CORRECT_PVP_NX-by-CORRECT_PVP_NY layer with CORRECT_PVP_NF features.
      // Sparse activity with no active neurons so file size doesn't change with number of features
      int emptydata[] = {80, 20, 2, CORRECT_PVP_NX, CORRECT_PVP_NY, CORRECT_PVP_NF, 1, 0, 4, 2, 1, 1, CORRECT_PVP_NX, CORRECT_PVP_NY, 0, 0, 0, 1, 0, 0, 0, 0, 0};
      size_t numwritten = PV_fwrite(emptydata, 23, sizeof(int), emptyinfile);
      if (numwritten != 23) {
         fprintf(stderr, "%s error writing placeholder data into input/correct.pvp file.\n", arguments->getProgramName());
      }
      PV_fclose(emptyinfile);
   }
   int status = rebuildandrun(initObj, NULL, &copyCorrectOutput, NULL, 0);
   return status;
}