Loading images in google colab

后端 未结 11 1897
梦如初夏
梦如初夏 2021-01-30 15:01

My Jupyter Notebook has the following code to upload an image to Colab:

from google.colab import files
uploaded = files.upload()

I get prompted

11条回答
  •  渐次进展
    2021-01-30 15:59

    You can use this function to plot ur images giving a path. using function is good thing to well structure your code.

    from PIL import Image # Image manipulations
    import matplotlib.pyplot as plt
    %matplotlib inline
    
    # This function is used more for debugging and showing results later. It plots the image into the notebook
    def imshow(image_path):
      # Open the image to show it in the first column of the plot 
      image = Image.open(image_path)  
      # Create the figure 
      fig = plt.figure(figsize=(50,5))
      ax = fig.add_subplot(1, 1, 1) 
      # Plot the image in the first axe with it's category name
      ax.axis('off')
      ax.set_title(image_path)
      ax.imshow(image) 
    

提交回复
热议问题