Esempio n. 1
0
def preprocess_input(*args, **kwargs):
    return mobilenet_v2.preprocess_input(*args, **kwargs)
Esempio n. 2
0
def preprocess_input(*args, **kwargs):
  return mobilenet_v2.preprocess_input(*args, **kwargs)
Esempio n. 3
0
def do_predict(model, batch, batch_headers, batch_size):
    images = preprocess_input(np.array(batch, dtype=np.float32))
    predicted = model.predict(images)[..., 1]
    for head, pred in zip(batch_headers, predicted):
        print("{:s},{:.2f}".format(str(head), pred), file=sys.stdout)
def batch_preprocess_input(x_batch, network):
    if network == 'Xception':
        x_batch = xception.preprocess_input(x_batch,
                                            backend=keras.backend,
                                            layers=keras.layers,
                                            models=keras.models,
                                            utils=keras.utils)
    elif network == 'VGG16':
        x_batch = vgg16.preprocess_input(x_batch,
                                         backend=keras.backend,
                                         layers=keras.layers,
                                         models=keras.models,
                                         utils=keras.utils)
    elif network == 'VGG19':
        x_batch = vgg19.preprocess_input(x_batch,
                                         backend=keras.backend,
                                         layers=keras.layers,
                                         models=keras.models,
                                         utils=keras.utils)
    elif network == 'ResNet50' or network == 'ResNet101' or network == 'ResNet152':
        x_batch = resnet.preprocess_input(x_batch,
                                          backend=keras.backend,
                                          layers=keras.layers,
                                          models=keras.models,
                                          utils=keras.utils)
    elif network == 'ResNet50V2' or network == 'ResNet101V2' or network == 'ResNet152V2':
        x_batch = resnet_v2.preprocess_input(x_batch,
                                             backend=keras.backend,
                                             layers=keras.layers,
                                             models=keras.models,
                                             utils=keras.utils)
    elif network == 'ResNeXt50' or network == 'ResNeXt101':
        x_batch = resnext.preprocess_input(x_batch,
                                           backend=keras.backend,
                                           layers=keras.layers,
                                           models=keras.models,
                                           utils=keras.utils)
    elif network == 'InceptionV3':
        x_batch = inception_v3.preprocess_input(x_batch,
                                                backend=keras.backend,
                                                layers=keras.layers,
                                                models=keras.models,
                                                utils=keras.utils)
    elif network == 'InceptionResNetV2':
        x_batch = inception_resnet_v2.preprocess_input(x_batch,
                                                       backend=keras.backend,
                                                       layers=keras.layers,
                                                       models=keras.models,
                                                       utils=keras.utils)
    elif network == 'MobileNet':
        x_batch = mobilenet.preprocess_input(x_batch,
                                             backend=keras.backend,
                                             layers=keras.layers,
                                             models=keras.models,
                                             utils=keras.utils)
    elif network == 'MobileNetV2':
        x_batch = mobilenet_v2.preprocess_input(x_batch,
                                                backend=keras.backend,
                                                layers=keras.layers,
                                                models=keras.models,
                                                utils=keras.utils)
    elif network == 'DenseNet121' or network == 'DenseNet169' or network == 'DenseNet201':
        x_batch = densenet.preprocess_input(x_batch,
                                            backend=keras.backend,
                                            layers=keras.layers,
                                            models=keras.models,
                                            utils=keras.utils)
    elif network == 'NASNetMobile' or network == 'NASNetLarge':
        x_batch = nasnet.preprocess_input(x_batch,
                                          backend=keras.backend,
                                          layers=keras.layers,
                                          models=keras.models,
                                          utils=keras.utils)
    elif 'EfficientNet' in network:
        x_batch = efficientnet.preprocess_input(x_batch)
    else:
        return None

    return x_batch