return cross_entropy model = VGG19(3) # model =ResNet50(3) opt = keras.optimizers.Adam(learning_rate=0.0001) # opt = keras.optimizers.SGD(learning_rate=1,momentum=0.001) model.compile(optimizer=opt, loss="categorical_crossentropy", metrics='accuracy') # model.compile(optimizer =opt, loss=weighted_categorical_crossentropy, metrics='accuracy') model.summary() dt = DataLoader() X_Data, Y_Data = dt.LoadTrainingData( "D:\Sergey\FluorocodeMain\FluorocodeMain\DataForTraining.npz") x_v, y_v = dt.LoadTrainingData( "D:\Sergey\FluorocodeMain\FluorocodeMain\DataForValidation.npz") history = model.fit(X_Data, Y_Data, batch_size=4, shuffle=True, epochs=100, validation_data=(x_v, y_v)) plt.plot(history.history['accuracy']) plt.plot(history.history['val_accuracy']) plt.title('Model accuracy')
# opt = keras.optimizers.Adam(learning_rate=0.001) opt = keras.optimizers.SGD(learning_rate=0.003, momentum=0.01) model.compile(optimizer=opt, loss="categorical_crossentropy", metrics='accuracy') model.summary() mcp_save = keras.callbacks.ModelCheckpoint( 'mdl_wts_step_fullgenomeStep2-Extra.hdf5', save_best_only=True, monitor='val_accuracy', mode='max') dt = DataLoader() # X_Data ,Y_Data = dt.LoadTrainingData("D:\Sergey\FluorocodeMain\FluorocodeMain\DataForTraining1D.npz") x_v, y_v = dt.LoadTrainingData( "D:\Sergey\FluorocodeMain\FluorocodeMain\DataForValidation1D.npz") history = model.fit(x_v, y_v, batch_size=8, epochs=15, validation_data=(x_v, y_v), callbacks=[mcp_save, RealDataEval(x_v, y_v)]) plt.plot(history.history['accuracy']) plt.plot(history.history['val_accuracy']) plt.title('Model accuracy') plt.ylabel('Accuracy')
pixelsz = 39.68 ResEnhancement = 2 # genomes = ['Other','CP014051','CP039296','CP000948'] # genomes = ['NC_000913.3','Other','CP014051','CP014787'] genomes = ['NC_000913.3', 'CP014051', 'CP014787', 'NZ_CP009467.1'] # genomes = ['CP014787'] # genomes = ['CP000948'] # genomes = ['CP014051','CP039296', 'CP009467.1','CP014787','CP000948'] AllLabels = [] AllProfiles = [] numsamples = 5000 Dt = DataConverter() Ds = DataLoader() for genome in genomes: EffLabeledTraces = [] SIMTRC = SIMTraces.TSIMTraces(genome, 1.66, 0.34, 0, 'TaqI', pixelsz) Gauss = Misc.GetGauss1d( size, Misc.FWHMtoSigma(Misc.GetFWHM(Wavelength, NA, ResEnhancement)), pixelsz) if genome != 'Other': Profiles = [] ReCuts = SIMTRC.GetTraceRestrictions() ReCutsInPx = SIMTRC.GetDyeLocationsInPixel(ReCuts) R = RTG.RandomTraceGenerator(Misc.kbToPx(100000, SIMTRC), Misc.kbToPx(20000, SIMTRC), numsamples)
""" import Core.Misc as Misc import Core.SIMTraces as SIMTraces import Core.RandomTraceGenerator as RTG import numpy as np from ImGen.ImGen import TrainImageGenerator from Core.DataHandler import DataConverter from Core.DataHandler import DataLoader genomes = ['CP014787', 'CP000948'] ImagesForAllGenomes = [] LabelsForAllGenomes = [] Dt = DataConverter() Ds = DataLoader() for genome in genomes: SIMTRC = SIMTraces.TSIMTraces(genome, 1.75, 0.34, 0, 'TaqI', 80) ReCuts = SIMTRC.GetTraceRestrictions() ReCutsInPx = SIMTRC.GetDyeLocationsInPixel(ReCuts) ReCutsInPx = ReCutsInPx[1:7000] R = RTG.RandomTraceGenerator(Misc.kbToPx(40000, SIMTRC), Misc.kbToPx(5000, SIMTRC), 16 * 4000) Traces = R.stratsample(np.asarray(ReCutsInPx)) EffLabeledTraces = R.GetEffLabelingRate(Traces, 0.85) IMGEN = TrainImageGenerator('D:\Sergey\TrainDirectory', 800, 16, 256, 510, 1.4, SIMTRC.PixelSize)