def get_model(name): assert name == 'vgg-16' model = keras.applications.vgg16.VGG16() model_preprocessing = keras.applications.resnet50.preprocess_input load_preprocess = lambda image_filepaths: model_preprocessing( load_images(image_filepaths, image_size=224)) wrapper = KerasWrapper(model, load_preprocess) wrapper.image_size = 224 return wrapper
def keras_model(module, model_function, image_size, identifier=None, model_kwargs=None): module = import_module(f"keras.applications.{module}") model_ctr, model_preprocessing = getattr(module, model_function), getattr(module, "preprocess_input") model = model_ctr(**(model_kwargs or {})) from model_tools.activations.keras import load_images load_preprocess = lambda image_filepaths: model_preprocessing(load_images(image_filepaths, image_size=image_size)) wrapper = KerasWrapper(model, load_preprocess, identifier=identifier) wrapper.image_size = image_size return wrapper
def get_model(name): assert name == 'resnet50' model = TFSlimModel.init('resnet-50_v1', net_name='resnet_v1_50', preprocessing_type='vgg', image_size=224, labels_offset=0) model_preprocessing = keras.applications.resnet50.preprocess_input load_preprocess = lambda image_filepaths: model_preprocessing( load_images(image_filepaths, image_size=224)) wrapper = KerasWrapper(model, load_preprocess) wrapper.image_size = 224 return wrapper
def load_preprocess_images(image_filepaths): images = load_images(image_filepaths) images = [transform(image) for image in images] images = [image.unsqueeze(0) for image in images] images = np.concatenate(images) return images