def OneKfold(i=0, saveloclist=None): modelloc = TrainModel(idfold=i, saveloclist=saveloclist) PredictKFold(modelloc, settings.options.dbfile, settings.options.outdir, kfolds=settings.options.kfolds, idfold=settings.options.idfold)
def OneKfold(i=0, datadict=None): k = settings.options.kfolds modelloc = TrainModel(idfold=i) (train_set, test_set, valid_set) = GetSetupKfolds(settings.options.dbfile, k, i) sumscore = 0 sumscorefloat = 0 for idtest in test_set: baseloc = '%s/%03d/%03d' % (settings.options.outdir, k, i) imgloc = '%s/%s' % (settings.options.rootlocation, datadict[idtest]['image']) segloc = '%s/%s' % (settings.options.rootlocation, datadict[idtest]['label']) outloc = '%s/label-%04d.nii.gz' % (baseloc, idtest) if settings.options.numepochs > 0 and ( settings.options.makepredictions or settings.options.makedropoutmap): if settings.options.makepredictions: predseg, predfloat = PredictModel(model=modelloc, image=imgloc, outdir=outloc) else: predseg, predfloat = PredictDropout(model=modelloc, image=imgloc, outdir=outloc, seg=segloc)
def OneKfold(i=0, datadict=None): k = settings.options.kfolds modelloc = TrainModel(idfold=i) (train_set,test_set) = GetSetupKfolds(settings.options.dbfile, k, i) print('train set',train_set) print('test set',test_set) for idtest in test_set: baseloc = '%s/%03d/%03d' % (settings.options.outdir, k, i) imgloc = '%s/%s' % (settings.options.rootlocation, datadict[idtest]['image']) segloc = '%s/%s' % (settings.options.rootlocation, datadict[idtest]['label']) outloc = '%s/label-%04d.nii.gz' % (baseloc, idtest) sumscore = 0
def OneKfold(i=0, datadict=None): k = settings.options.kfolds modelloc = TrainModel(idfold=i) (train_set,test_set) = GetSetupKfolds(settings.options.dbfile, k, i) print('train set',train_set) print('test set',test_set) sumscore = 0 sumscorefloat = 0 for idtest in test_set: baseloc = '%s/%03d/%03d' % (settings.options.outdir, k, i) imgloc = '%s/%s' % (settings.options.rootlocation, datadict[idtest]['image']) segloc = '%s/%s' % (settings.options.rootlocation, datadict[idtest]['label']) outloc = '%s/label-%04d.nii.gz' % (baseloc, idtest) if settings.options.numepochs > 0 and (settings.options.makepredictions or settings.options.makedropoutmap) # as I train imagepredict = nib.load(imgloc) imageheader = imagepredict.header numpypredict = imagepredict.get_data().astype(settings.IMG_DTYPE) allseg = nib.load(segloc).get_data().astype(settings.SEG_DTYPE) liver_idx = allseg > 0 tumor_idx = allseg > 1 seg_liver = np.zeros_like(allseg) seg_liver[liver_idx] = 1 seg_tumor = np.zeros_like(allseg) seg_tumor[tumor_idx] = 1 image_liver = seg_liver*numpypredict - (1.0 - seg_liver) image_liver = image_liver.astype(settings.IMG_DTYPE) if settings.options.makepredictions: predseg, predfloat = PredictModelFromNumpy(model=modelloc, image=image_liver, imageheader=imageheader, outdir=outloc ) else: predseg, predfloat = PredictDropoutFromNumpy(model=modelloc, image=image_liver, imageheader=imageheader, outdir=outloc) score_float = dsc_l2_3D(seg_tumor.astype(settings.IMG_DTYPE), predfloat) sumscorefloat += score_float print(idtest, "\t", sumscorefloat) print(k, " avg dice:\t", sumscorefloat/len(test_set))
def OneKfold(i=0, datadict=None): k = settings.options.kfolds modelloc = TrainModel(idfold=i) (train_set, test_set) = GetSetupKfolds(settings.options.dbfile, k, i) for idtest in test_set: baseloc = '%s/%03d/%03d' % (settings.options.outdir, k, i) imgloc = '%s/%s' % (settings.options.rootlocation, datadict[idtest]['image']) segloc = '%s/%s' % (settings.options.rootlocation, datadict[idtest]['label']) outloc = '%s/label-%04d.nii.gz' % (baseloc, idtest) sumscore = 0 if settings.options.numepochs > 0 and settings.options.makepredictions: # doing K-fold prediction as I train imagepredict = nib.load(imgloc) imageheader = imagepredict.header numpypredict = imagepredict.get_data().astype(settings.IMG_DTYPE) allseg = nib.load(segloc).get_data().astype(settings.SEG_DTYPE) liver_idx = allseg > 0 tumor_idx = allseg > 1 seg_liver = np.zeros_like(allseg) seg_liver[liver_idx] = 1 seg_tumor = np.zeros_like(allseg) seg_tumor[tumor_idx] = 1 image_liver = seg_liver * numpypredict - 100.0 * (1.0 - seg_liver) image_liver = image_liver.astype(settings.IMG_DTYPE) predseg = PredictModelFromNumpy(model=modelloc, image=image_liver, imageheader=imageheader, outdir=outloc) score = dsc_int_3D(seg_tumor, predseg) sumscore += score print(idtest, "\t", score) print(k, " avg dice:\t", sumscore / len(test_set))
import settings from settings import process_options, perform_setup (options, args) = process_options() IMG_DTYPE, SEG_DTYPE, _globalnpfile, _globalexpectedpixel, _nx, _ny = perform_setup( options) print('database file: %s ' % settings._globalnpfile) from setupmodel import GetDataDictionary, BuildDB from trainmodel import TrainModel from predictmodel import PredictModel from kfolds import OneKfold, Kfold if options.builddb: BuildDB() if options.kfolds > 1: if options.idfold > -1: databaseinfo = GetDataDictionary(options.dbfile) OneKfold(i=options.idfold, datadict=databaseinfo) else: Kfold() if options.trainmodel and options.kfolds == 1: # no kfolds, i.e. k=1 TrainModel() if options.predictmodel: PredictModel() if ((not options.builddb) and (not options.trainmodel) and (not options.predictmodel) and (options.kfolds == 1)): print("parser error")
start = time.time() align = NaiveDlib(args.dlibFaceMean, args.dlibFacePredictor) #net = openface.TorchWrap(args.networkModel, imgDim=args.imgDim, cuda=args.cuda) if args.verbose: print("Loading the dlib and OpenFace models took {} seconds.".format( time.time() - start)) ################################################################################### from frameextractor import FrameExtractor from labelframe import LabelFrame from trainmodel import TrainModel FE = FrameExtractor() LF = LabelFrame() TM = TrainModel() print "====== Welcome to DriveSmart Training Module ======" print "Enter the path to the video folder:" videoPath = raw_input('--->') print "Enter the text file containing list of videos with closed eyes:" closedTextPath = raw_input('--->') print "Enter the text file containing list of videos with open eyes:" openTextPath = raw_input('--->') #Extracting Frames FE.setVideoFileName(videoPath) FE.fetchFrame(closedTextPath, 0) FE.fetchFrame(openTextPath, 1) #Extracting Eye Patches
print('no list of tumor .npy files given for training') quit() else: saveloclist = options.datafiles_tumor else: print('not specified liver vs tumor') quit() print('files already generated: using', saveloclist) if options.kfolds > 1: if options.idfold > -1: OneKfold(i=options.idfold, saveloclist=saveloclist) else: Kfold(saveloclist=saveloclist) else: TrainModel(saveloclist=saveloclist) if options.predictmodel: if options.predictfromcsv: PredictCSV(modelloc=options.predictmodel, outdir=options.outdir, indir=options.predictfromcsv) else: PredictNifti(model, options.outdir + '/predictions/pred', options.predictimage, segloc=None) PredictModel()
# To bypass certificate errors try: _create_unverified_https_context = ssl._create_unverified_context except AttributeError: pass else: ssl._create_default_https_context = _create_unverified_https_context app = Flask(__name__) # Class Objects data_processor = DataProcess() train_model = TrainModel() # Pull all available data starting year 2000 until today start_date = datetime(2000, 1, 1) end_date = datetime.date(datetime.today()) # Input Arguments apikey = 'JXYRIAIGOFQQEYU6' apikey2 = 'OMX6JTTUJ7VZ4MOJ' apikey3 = 'O4170I9AFRMU1MWM' apikey4 = 'L7WQ5800OSKGRWRD' symbol = 'SPY' interval = 'daily' interval_vwap = '60min' time_period_cci_5 = '5' time_period_cci_20 = '20'