def get_model(): global INPUT_SHAPE if args.net.startswith("resnet50"): if args.net == "resnet50": INPUT_SHAPE = (224, 224, 3) elif args.net == "resnet50_112": INPUT_SHAPE = (112, 112, 3) return resnet50_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining) elif args.net.startswith('senet') or args.net.startswith( 'resnet') or args.net.startswith('vgg'): INPUT_SHAPE = (112, 112, 3) if args.net.endswith("_112") else (224, 224, 3) if args.pretraining.startswith('imagenet'): if args.net.startswith('senet') or args.net.startswith('resnet'): return senet_model_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining) else: return vgg16_keras_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining) else: return vggface_custom_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining, args.net, args.lpf_size) elif args.net == 'mobilenet96': INPUT_SHAPE = (96, 96, 3) return mobilenet_96_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining) elif args.net == 'mobilenet224': INPUT_SHAPE = (224, 224, 3) return mobilenet_224_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining) elif args.net == 'mobilenet64_bio': INPUT_SHAPE = (64, 64, 3) return mobilenet_64_build(INPUT_SHAPE, NUM_CLASSES) elif args.net.startswith('mobilenetv3large'): if args.net == 'mobilenetv3large': INPUT_SHAPE = (224, 224, 3) elif args.net == 'mobilenetv3large_112': INPUT_SHAPE = (112, 112, 3) return mobilenet_v3_large_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining) elif args.net == 'mobilenetv3small': INPUT_SHAPE = (224, 224, 3) return mobilenet_v3_small_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining) elif args.net == 'densenet121bc': INPUT_SHAPE = (224, 224, 3) return densenet_121_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining, args.lpf_size) elif args.net.startswith('xception'): INPUT_SHAPE = (71, 71, 3) if args.net == 'xception71' else (299, 299, 3) return xception_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining, args.lpf_size) elif args.net == "shufflenet224": INPUT_SHAPE = (224, 224, 3) return shufflenet_224_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining) elif args.net == "squeezenet": INPUT_SHAPE = (224, 224, 3) return squeezenet_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining)
def get_model(): global INPUT_SHAPE if args.net.startswith('senet') or args.net.startswith( 'resnet') or args.net.startswith('vgg'): INPUT_SHAPE = (224, 224, 3) if args.pretraining.startswith('imagenet'): if args.net.startswith('senet') or args.net.startswith('resnet'): return senet_model_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining) else: return vgg16_keras_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining) else: print("VGGFACE Network") return vggface_custom_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining, args.net, args.lpf_size) elif args.net == 'mobilenet96': INPUT_SHAPE = (96, 96, 3) return mobilenet_96_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining) elif args.net == 'mobilenet224': INPUT_SHAPE = (224, 224, 3) return mobilenet_224_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining) elif args.net == 'mobilenet64_bio': INPUT_SHAPE = (64, 64, 3) return mobilenet_64_build(INPUT_SHAPE, NUM_CLASSES) elif args.net == 'densenet121bc': INPUT_SHAPE = (224, 224, 3) return densenet_121_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining, args.lpf_size) elif args.net.startswith('xception'): INPUT_SHAPE = (71, 71, 3) if args.net == 'xception71' else (299, 299, 3) return xception_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining, args.lpf_size) elif args.net == "shufflenet224": INPUT_SHAPE = (224, 224, 3) return shufflenet_224_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining) elif args.net == "squeezenet": INPUT_SHAPE = (224, 224, 3) return squeezenet_build(INPUT_SHAPE, NUM_CLASSES, args.pretraining)
def load_keras_model(filepath): main_filepath = os.path.split(os.path.split(filepath)[0])[1] print("Loading from:", main_filepath) if 'vgg16' in main_filepath: model = vgg16_keras_build()[0] model.load_weights(filepath) INPUT_SHAPE = (224, 224, 3) else: model = keras.models.load_model(filepath, custom_objects=custom_objects) if 'mobilenet96' in main_filepath: INPUT_SHAPE = (96, 96, 3) elif 'mobilenet64_bio' in main_filepath: INPUT_SHAPE = (64, 64, 3) elif 'xception71' in main_filepath: INPUT_SHAPE = (71, 71, 3) elif 'xception' in main_filepath: INPUT_SHAPE = (299, 299, 3) else: INPUT_SHAPE = (224, 224, 3) return model, INPUT_SHAPE