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; }
int TrainingLayer::readTrainingLabels(const char * filename, int ** trainingLabelsFromFile) { PV_Stream * instream = PV_fopen(filename, "r", false/*verifyWrites*/); if( instream == NULL ) { fprintf( stderr, "TrainingLayer error opening \"%s\": %s\n", filename, strerror(errno) ); *trainingLabelsFromFile = NULL; return 0; } int didReadLabel; int n = 0; int label; int * labels = NULL; int * oldlabels; do { didReadLabel = fscanf(instream->fp, "%d", &label); updatePV_StreamFilepos(instream); // to recalculate instream->filepos since it's not easy to tell how many characters were read switch( didReadLabel ) { case 0: PV_fseek( instream, 1L, SEEK_CUR ); break; case 1: n++; oldlabels = labels; labels = (int *) malloc((size_t) n * sizeof(int) ); assert(labels); for(int k=0; k<n-1; k++) labels[k] = oldlabels[k]; labels[n-1] = label; free(oldlabels); break; } } while( didReadLabel != EOF ); PV_fclose(instream); *trainingLabelsFromFile = labels; return n; }
Movie::~Movie() { if (getParent()->icCommunicator()->commRank()==0 && filenamestream != NULL && filenamestream->isfile) { PV_fclose(filenamestream); } if (getParent()->icCommunicator()->commRank()==0 && timestampFile != NULL && timestampFile->isfile) { PV_fclose(timestampFile); } if(movieOutputPath){ free(movieOutputPath); } if(framePath){ for(int b = 0; b < parent->getNBatch(); b++){ if(framePath[b]){ free(framePath[b]); } } free(framePath); } if(startFrameIndex){ free(startFrameIndex); } if(skipFrameIndex){ free(skipFrameIndex); } if(paramsStartFrameIndex){ free(paramsStartFrameIndex); } if(paramsSkipFrameIndex){ free(paramsSkipFrameIndex); } if(batchMethod){ free(batchMethod); } if(batchPos){ free(batchPos); } if(frameNumbers){ free(frameNumbers); } }
MoviePvp::~MoviePvp() { //if (imageData != NULL) { // delete imageData; // imageData = NULL; //} //if (getParent()->icCommunicator()->commRank()==0 && filenamestream != NULL && filenamestream->isfile) { // PV_fclose(filenamestream); //} //free(fileOfFileNames); fileOfFileNames = NULL; if (getParent()->icCommunicator()->commRank()==0 && timestampFile != NULL && timestampFile->isfile) { PV_fclose(timestampFile); } free(movieOutputPath); free(paramsStartFrameIndex); free(startFrameIndex); free(paramsSkipFrameIndex); free(skipFrameIndex); free(frameNumbers); free(batchMethod); }
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, ©CorrectOutput, NULL, 0); return status; }
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, ©CorrectOutput, NULL, 0); return status; }