predict.py
def predict(image_path, model, topkl, device):
    ''' Predict the class (or classes) of an image using a trained deep learning model.
    '''
    model.to(device)
    model.eval()
    img = process_image(image_path)
    img = img.numpy()
    img = torch.from_numpy(np.array([img])).float()

    with torch.no_grad():
        output = model.forward(img.device())
        
    probability = torch.exp(output).data
    
    return probability.topk(topk)
 Predict the class (or classes) of an image using a trained deep learning model.
    
Predict the class (or classes) of an image using a trained deep learning model.
Predict the class ( or classes ) of an image using a trained deep learning model .
def predict(image_path, model, topkl, device):
    model.to(device)
    model.eval()
    img = process_image(image_path)
    img = img.numpy()
    img = torch.from_numpy(np.array([img])).float()
    with torch.no_grad():
        output = model.forward(img.device())
    probability = torch.exp(output).data
    return probability.topk(topk)
def predict ( image_path , model , topkl , device ) : model . to ( device ) model . eval ( ) img = process_image ( image_path ) img = img . numpy ( ) img = torch . from_numpy ( np . array ( [ img ] ) ) . float ( ) with torch . no_grad ( ) : output = model . forward ( img . device ( ) ) probability = torch . exp ( output ) . data return probability . topk ( topk )
Predict the class (or classes) of an image using a trained deep learning model.
Predict the class ( or classes ) of an image using a trained deep learning model .
''' Predict the class (or classes) of an image using a trained deep learning model.
    '''
image_path
model
topkl
device