# Initialize the training and validation dataset generators trainGen = HDF5DatasetGenerator(dbPath=data_config.TRAIN_HDF5, batchSize=128, preprocessor=[pp, mp, iap], aug=None, classes=2) valGen = HDF5DatasetGenerator(dbPath=data_config.VAL_HDF5, batchSize=128, preprocessor=[sp, mp, iap], classes=2) # Initialize the optimizer print("[INFO] compiling model..,") opt = Adam(lr=1e-3) model = AlexNet.build(width=227, height=227, depth=3, classes=2, reg=0.0002) model.compile(loss="binary_crossentropy", optimizer=opt, metrics=["accuracy"]) # Construct the set of callbacks path = os.path.sep.join( [data_config.OUTPUT_PATH, "{}.png".format(os.getpid())]) callbacks = [TrainingMonitor(path)] # train the network model.fit_generator(trainGen.generator(), steps_per_epoch=trainGen.numImages // 128, validation_data=valGen.generator(), validation_steps=valGen.numImages // 128, epochs=75, max_queue_size=128 * 2, callbacks=None,
batch_size=batch_size, class_mode='categorical', subset='validation', classes=CLASSES) tbCallBack = TensorBoard(log_dir='./logs', histogram_freq=0, write_graph=True, write_images=True) # initialize the optimizer print("[INFO] compiling model...") opt = Adam(lr=0.5e-3) model = AlexNet.build(width=height, height=width, depth=channel, classes=num_class, reg=0.0002) model.compile(loss="categorical_crossentropy", optimizer=opt, metrics=["accuracy"]) # train the network model.fit_generator( train_generator, steps_per_epoch=train_generator.samples // batch_size, validation_data=validation_generator, validation_steps=validation_generator.samples // batch_size, epochs=nb_epochs, # 0 = silent, 1 = progress bar, 2 = one line per epoch. callbacks=[tbCallBack],
parser.add_argument("-nn", "--network", required=True, \ help="name of neural network") parser.add_argument("-o", "--output", required=True, \ help="path to output pictures") args = vars(parser.parse_args()) networkBanks = { "vgg16": VGG16(weights="imagenet"), "vgg19": VGG19(weights="imagenet"), "kerasresnet50": KerasResNet50(weights="imagenet"), "inceptionv3": InceptionV3(weights="imagenet"), "shallownet": ShallowNet.build(height=28, width=28, depth=3, classes=10), "lenet": LeNet.build(height=28, width=28, depth=3, classes=10), "minivgg": MiniVGGNet.build(height=28, width=28, depth=3, classes=10), #"kfer_lenet" : KFER_LeNet.build(height=48, width=48, depth=3, classes=7), "alexnet": AlexNet.build(height=227, width=227, depth=3, classes=1000), "alexnet2": AlexNet2.build(height=227, width=227, depth=3, classes=1000), "resnet50": ResNet50(height=224, width=224, depth=3, classes=10), "resnet101": ResNet101(height=224, width=224, depth=3, classes=10), "resnet152": ResNet152(height=224, width=224, depth=3, classes=10), } model = networkBanks[args["network"]] arch_path = os.path.join(args["output"], \ "{}_architecture.png".format(args["network"])) """ show_shapes = print out each layer's shape; or use tf.compat.v1.keras.utils.plot_model() / tf.keras.utils.load_model(), with rankdir = TB/LR, plotting layers in V/H direction