【问题标题】:Google Colab: How to access Images?Google Colab:如何访问图像?
【发布时间】:2021-04-01 21:58:53
【问题描述】:

我无法在 google colab 中运行此代码,我已经等了 15 分钟,它没有给出任何错误,但它也不起作用。这个符号根本停不下来。你们知道可能是什么问题吗?

DATADIR ='/content/drive/MyDrive/Colab_Notebooks/cat-dog/PetImages'
categories =["Cat","Dog"]
training_data =[]

def create_training_data():
    for category in categories: 
        path = os.path.join(DATADIR,category) 
        class_num =categories.index(category)
        for img in os.listdir(path):
            try: 
                img_arr =cv2.imread(os.path.join(path,img),cv2.IMREAD_GRAYSCALE)
                new_array =cv2.resize(img_arr, (50,50))
                training_data.append([new_array,class_num])
            
            except Exception as e:
                pass
            
        
create_training_data()

【问题讨论】:

  • 您是否将您的驱动器与 colab 合并?
  • 是的,我做到了。我刚刚尝试使用 for 循环的相同代码(我没有使用函数)并且我能够看到图片但是当我尝试创建函数时不知何故,它不起作用..
  • 尝试将'categories'和'DATADIR'作为函数create_training_data(categories,DATADIR)的参数传递
  • 不幸的是......好吧,我想我会使用另一个平台谢谢你的回答。

标签: python tensorflow opencv image-processing google-colaboratory


【解决方案1】:

你需要安装你的谷歌驱动器

这是你的做法

Mounting google drive in colab

【讨论】:

    【解决方案2】:

    我认为你的路径是错误的。您需要在“Colab”和“Notebooks”之间留一个空格。

    DATADIR ='/content/drive/MyDrive/Colab Notebooks/cat-dog/PetImages'
    

    【讨论】:

    • 昨晚终于解决了,其实没有问题。在 'except Exception as e:' 之后,我将 'pass' 更改为 'print(str(e))' 并以某种方式解决了问题,它就像一个魅力!
    【解决方案3】:

    昨晚终于解决了,其实没有问题。在 'except Exception as e:' 之后,我将 'pass' 更改为 'print(str(e))' 并以某种方式解决了问题,它就像一个魅力!

    []

    【讨论】:

      猜你喜欢
      • 2021-08-14
      • 2019-12-16
      • 1970-01-01
      • 2020-03-06
      • 2019-05-20
      • 2020-03-22
      • 1970-01-01
      • 2018-07-07
      • 2018-11-10
      相关资源
      最近更新 更多