【问题标题】:Can we load images from image URLs directly to CNN models in Keras/TensorFlow without storing the images in a local directory?我们可以将图像从图像 URL 直接加载到 Keras/TensorFlow 中的 CNN 模型而不将图像存储在本地目录中吗?
【发布时间】:2019-12-04 19:14:12
【问题描述】:

我想从图像 URL 中检索图像并将它们输入 keras 中的 CNN 模型,但我不想将图像存储在本地文件夹中?

有没有办法做到这一点?

【问题讨论】:

    标签: deep-learning computer-vision conv-neural-network


    【解决方案1】:

    您可以使用 skimage.io 从 URL 读取图像。阅读后,您应该展开数组。例如:图像阵列形状为 (64,64,3)。展开后(1,64,64,3)

    from skimage import io
    import tensorflow as tf
    
    #Load model
    model = tf.load_model("model.h5")
    
    # Read image from web image
    image_array = io.imread('https://i.stack.imgur.com/QupKb.png')
    
    img_array = tf.expand_dims(img_array, 0) 
    predictions = model.predict(img_array)
    
    

    【讨论】:

      【解决方案2】:

      您可以使用skimage 从这样的图像 URL 中读取图像

      from skimage import io
      import cv2
      
      # Read image from web image
      image = io.imread('https://i.stack.imgur.com/QupKb.png')
      
      # Display image
      cv2.imshow('image', image)
      cv2.waitKey()
      

      【讨论】:

      • 知道了。但是如果我想直接加载到模型中?所以我将图像 URL 存储在数据框中并想使用数据框中的 Imagedatagenerator.flow 吗?类似的事情可能吗?
      • @DebayanMitra 你应该为此打开一个新问题,我确定它可能
      猜你喜欢
      • 2023-03-23
      • 1970-01-01
      • 2019-09-22
      • 2019-08-07
      • 2017-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多