original_docstring:  Predict the class (or classes) of an image using a trained deep learning model.
      
docstring: Predict the class (or classes) of an image using a trained deep learning model.
docstring_tokens: Predict the class ( or classes ) of an image using a trained deep learning model .
code: def predict(image_path, model, topk):
      ''' Predict the class (or classes) of an image using a trained deep learning model.
      '''    
      device = 'cpu'
      image = process_image(image_path)  
      image = torch.from_numpy(image) 
      image = image.unsqueeze_(0)
      image = image.float()
      image = image.to(device)
      
      model.to(device)       
      model.eval()
      
      with torch.no_grad():  
          logps = model.forward(image)
      ps = torch.exp(logps)
      top_p, top_class = ps.topk(topk, dim = 1)
      top_p, top_class = np.array(top_p)[0], np.array(top_class)[0]
  
      idx_to_class = {v: k for k, v in model.class_to_idx.items()}
      top_class = [idx_to_class[i] for i in top_class]
      return top_p, top_class
code_tokens: def predict ( image_path , model , topk ) : device = 'cpu' image = process_image ( image_path ) image = torch . from_numpy ( image ) image = image . unsqueeze_ ( 0 ) image = image . float ( ) image = image . to ( device ) model . to ( device ) model . eval ( ) with torch . no_grad ( ) : logps = model . forward ( image ) ps = torch . exp ( logps ) top_p , top_class = ps . topk ( topk , dim = 1 ) top_p , top_class = np . array ( top_p ) [ 0 ] , np . array ( top_class ) [ 0 ] idx_to_class = { v : k for k , v in model . class_to_idx . items ( ) } top_class = [ idx_to_class [ i ] for i in top_class ] return top_p , top_class
short_docstring: Predict the class (or classes) of an image using a trained deep learning model.
short_docstring_tokens: Predict the class ( or classes ) of an image using a trained deep learning model .
comment: ''' Predict the class (or classes) of an image using a trained deep learning model.
      '''