[英]Trying to print image count
I am new to Python and I am trying to start CNN for one project.我是 Python 的新手,我正在尝试为一个项目启动 CNN。 I mounted the gdrive and I am trying to download images from the gdrive directory.
我安装了 gdrive 并尝试从 gdrive 目录下载图像。 After, I am trying to count the images that I have in that directory.
之后,我试图计算该目录中的图像。 Here is my code:
这是我的代码:
import pathlib
dataset_dir = "content/drive/My Drive/Species_Samples"
data_dir = tf.keras.utils.get_file('Species_Samples', origin=dataset_dir, untar=True)
data_dir = pathlib.Path(data_dir)
image_count = len(list(data_dir('*/*.png')))
print(image_count)
However, I get the following error.但是,我收到以下错误。
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-78-e5d9409807d9> in <module>()
----> 1 image_count = len(list(data_dir('*/*.png')))
2 print(image_count)
TypeError: 'PosixPath' object is not callable
Can you help, please?你能帮忙吗?
After suggestion, my code looks like this:建议后,我的代码如下所示:
import pathlib
data_dir = pathlib.Path("content/drive/My Drive/Species_Samples/")
count = len(list(data_dir.rglob("*.png")))
print(count)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.