【发布时间】: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