aws_lambda/pytorch-serverless/aws/pytorch/prediction.py
def predict(model, classes, image_tensor):
    """Predicts the class of an image_tensor."""

    start_time = time.time()
    predict_values = model(image_tensor)
    logger.info("Inference time: {} seconds".format(time.time() - start_time))
    softmaxed = F.softmax(predict_values, dim=1)
    probability_tensor, index = torch.max(softmaxed, dim=1)
    prediction = classes[index]
    probability = "{:1.2f}".format(probability_tensor.item())
    logger.info(f'Predicted class is {prediction} with a probability of {probability}')
    return {'class': prediction, 'probability': probability}
Predicts the class of an image_tensor.
Predicts the class of an image_tensor.
Predicts the class of an image_tensor .
def predict(model, classes, image_tensor):
    start_time = time.time()
    predict_values = model(image_tensor)
    logger.info("Inference time: {} seconds".format(time.time() - start_time))
    softmaxed = F.softmax(predict_values, dim=1)
    probability_tensor, index = torch.max(softmaxed, dim=1)
    prediction = classes[index]
    probability = "{:1.2f}".format(probability_tensor.item())
    logger.info(f'Predicted class is {prediction} with a probability of {probability}')
    return {'class': prediction, 'probability': probability}
def predict ( model , classes , image_tensor ) : start_time = time . time ( ) predict_values = model ( image_tensor ) logger . info ( "Inference time: {} seconds" . format ( time . time ( ) - start_time ) ) softmaxed = F . softmax ( predict_values , dim = 1 ) probability_tensor , index = torch . max ( softmaxed , dim = 1 ) prediction = classes [ index ] probability = "{:1.2f}" . format ( probability_tensor . item ( ) ) logger . info ( f'Predicted class is {prediction} with a probability of {probability}' ) return { 'class' : prediction , 'probability' : probability }
Predicts the class of an image_tensor.
Predicts the class of an image_tensor .
"""Predicts the class of an image_tensor."""
model
classes
image_tensor