我正在尝试运行以下代码并从另一个笔记本中调用一个函数,但我似乎无法弄清楚将所有图像数据加载到目录中的情况。
for index, row in dataset.iterrows():
x.append(array(ela_form(row[1], 90).resize((128, 128))).flatten() / 255.0)
y.append(row[0])
iam调用的功能是我导入的另一个笔记本中的ela_form。
def ela_form(path, quality):
im_name = path
rename_image = im_name.split('.')[0] + '.resaved.jpg'
ELA_filename = im_name.split('.')[0] + '.ela.png'
im = Image.open(im_name).convert('RGB')
im.save(rename_image, 'JPEG', quality=quality)
resaved_im = Image.open(rename_image)
ela_image = ImageChops.difference(im, resaved_im)
extrema = ela_image.getextrema()
max_diff = max([ex[1] for ex in extrema])
if max_diff == 0:
max_diff = 1
scale = 255.0 / max_diff
ela_image = ImageEnhance.Brightness(ela_image).enhance(scale)
return ela_image
我的图像存储在'dataset \ Training_Data_Preprocessed'
Dataset.csv存储在'dataset \ Dataset.csv
中> Error:FileNotFoundError Traceback (most recent
> call last) <ipython-input-16-920134a3a471> in <module>
> 3 for index, row in dataset.iterrows():
> 4
> ----> 5 x.append(array(ela_form(row[1], 90).resize((128, 128))).flatten() / 255.0)
> 6 y.append(row[0])
>
> ~\Desktop\Jupyter Notebooks\ELA.ipynb in ela_form(path, quality)
>
> D:\Anaconda\lib\site-packages\PIL\Image.py in open(fp, mode) 2807
> 2808 if filename:
> -> 2809 fp = builtins.open(filename, "rb") 2810 exclusive_fp = True 2811
>
> FileNotFoundError: [Errno 2] No such file or directory: 'im1_o.bmp'