从Python中的不同文件夹中读取文件列表
for root, dirs, files in os.walk(os.getcwd()):
for dirct in dirs:
lis_sal_map =[]
gt = ''
for name in files:
(base, ext) = os.path.splitext(name) # split base and extension
if ext in ('.jpg'): # check the extension
gt = name
print("gt old is", gt)
if ext in ('.png'):
#full_name = os.path.join(root, name)
lis_sal_map.append(name)
print("list sal map", lis_sal_map)
print("gt before file", gt)
img_gt = Image.open(gt)
numpydata_in = np.array(img_gt).astype('uint8')
numpydata_out = list_sal_map[0]
nss = nss(numpydata_in, numpydata_out)
print("nss is", nss)
我有18个文件夹,每个文件夹包含10张图像,一个图像作为地面真理,另一些作为预测的图像。我正在尝试编写一个程序,该程序将逐一访问这18个文件夹并比较每个文件夹中的图像。您能帮我解决问题吗?我获得的当前输出如下:
list sal map []
list sal map []
gt befoe file
Traceback (most recent call last):
fp.seek(0)
AttributeError: 'str' object has no attribute 'seek'
During handling of the above exception, another exception occurred:
Trace back (most recent call last):
File "result_auto.py", line 61, in <module>
img_gt = Image.open(gt)
File "anaconda3/lib/python3.8/site-packages/PIL/Image.py", line 2897, in open
fp = io.BytesIO(fp.read())
AttributeError: 'str' object has no attribute 'read'
for root, dirs, files in os.walk(os.getcwd()):
for dirct in dirs:
lis_sal_map =[]
gt = ''
for name in files:
(base, ext) = os.path.splitext(name) # split base and extension
if ext in ('.jpg'): # check the extension
gt = name
print("gt old is", gt)
if ext in ('.png'):
#full_name = os.path.join(root, name)
lis_sal_map.append(name)
print("list sal map", lis_sal_map)
print("gt before file", gt)
img_gt = Image.open(gt)
numpydata_in = np.array(img_gt).astype('uint8')
numpydata_out = list_sal_map[0]
nss = nss(numpydata_in, numpydata_out)
print("nss is", nss)
I have 18 folders each containing 10 images, with one as ground truth and others as predicted images. I am trying to write a program that will access these 18 folders one by one and compare the images within each folder. Can you help me with where it is going wrong? The current output that I am getting is like below:
list sal map []
list sal map []
gt befoe file
Traceback (most recent call last):
fp.seek(0)
AttributeError: 'str' object has no attribute 'seek'
During handling of the above exception, another exception occurred:
Trace back (most recent call last):
File "result_auto.py", line 61, in <module>
img_gt = Image.open(gt)
File "anaconda3/lib/python3.8/site-packages/PIL/Image.py", line 2897, in open
fp = io.BytesIO(fp.read())
AttributeError: 'str' object has no attribute 'read'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论