Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

数据提取过程为什么找不到文件夹,我已经创建了但是找不到 #41

Open
qqbangbangbang opened this issue Mar 29, 2024 · 7 comments

Comments

@qqbangbangbang
Copy link

Traceback (most recent call last):
File "dataprocessing.py", line 50, in
h5f = h5py.File(os.path.join('.\data',
File "/root/miniconda3/envs/cddfuse/lib/python3.8/site-packages/h5py/_hl/files.py", line 562, in init
fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr)
File "/root/miniconda3/envs/cddfuse/lib/python3.8/site-packages/h5py/_hl/files.py", line 241, in make_fid
fid = h5f.create(name, h5f.ACC_TRUNC, fapl=fapl, fcpl=fcpl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py/h5f.pyx", line 122, in h5py.h5f.create
FileNotFoundError: [Errno 2] Unable to synchronously create file (unable to open file: name = '.\data/MSRS_train_imgsize_128_stride_200.h5', errno = 2, error message = 'No such file or directory', flags = 13, o_flags = 242)

@qqbangbangbang
Copy link
Author

./data/MSRS_train_imgsize_128_stride_200.h5 为什么创建不了这个呢

@qqbangbangbang
Copy link
Author

在测试阶段,这个错误不知道该怎么解决
Traceback (most recent call last):
File "test_IVF.py", line 53, in
img_save(fi, img_name.split(sep='.')[0], test_out_folder)
File "/root/autodl-tmp/MMIF-CDDFuse-main/utils/img_read_save.py", line 21, in img_save
imsave(os.path.join(savepath, "{}.png".format(imagename)),image)
File "/root/miniconda3/envs/cddfuse/lib/python3.8/site-packages/skimage/io/_io.py", line 143, in imsave
return call_plugin('imsave', fname, arr, plugin=plugin, **plugin_args)
File "/root/miniconda3/envs/cddfuse/lib/python3.8/site-packages/skimage/io/manage_plugins.py", line 207, in call_plugin
return func(*args, **kwargs)
File "/root/miniconda3/envs/cddfuse/lib/python3.8/site-packages/imageio/v2.py", line 397, in imwrite
return file.write(im, **kwargs)
File "/root/miniconda3/envs/cddfuse/lib/python3.8/site-packages/imageio/core/v3_plugin_api.py", line 367, in exit
self.close()
File "/root/miniconda3/envs/cddfuse/lib/python3.8/site-packages/imageio/plugins/pillow.py", line 144, in close
self._flush_writer()
File "/root/miniconda3/envs/cddfuse/lib/python3.8/site-packages/imageio/plugins/pillow.py", line 485, in _flush_writer
primary_image.save(self._request.get_file(), **self.save_args)
File "/root/miniconda3/envs/cddfuse/lib/python3.8/site-packages/PIL/Image.py", line 2439, in save
save_handler(self, fp, filename)
File "/root/miniconda3/envs/cddfuse/lib/python3.8/site-packages/PIL/PngImagePlugin.py", line 1282, in _save
raise OSError(msg) from e
OSError: cannot write mode F as PNG

@KeyWu
Copy link

KeyWu commented Jun 5, 2024

./data/MSRS_train_imgsize_128_stride_200.h5 为什么创建不了这个呢

在目录下建一个data文件夹就行

@1JKW1
Copy link

1JKW1 commented Jun 30, 2024

Here's the code I modified to run without errors!
import os
import h5py
import numpy as np
from tqdm import tqdm
from skimage.io import imread

def get_img_file(file_name):
imagelist = []
for parent, dirnames, filenames in os.walk(file_name):
for filename in filenames:
if filename.lower().endswith(('.bmp', '.dib', '.png', '.jpg', '.jpeg', '.pbm', '.pgm', '.ppm', '.tif', '.tiff', '.npy')):
imagelist.append(os.path.join(parent, filename))
return imagelist

def rgb2y(img):
y = img[0:1, :, :] * 0.299000 + img[1:2, :, :] * 0.587000 + img[2:3, :, :] * 0.114000
return y

def Im2Patch(img, win, stride=1):
k = 0
endc = img.shape[0]
endw = img.shape[1]
endh = img.shape[2]
patch = img[:, 0:endw-win+0+1:stride, 0:endh-win+0+1:stride]
TotalPatNum = patch.shape[1] * patch.shape[2]
Y = np.zeros([endc, win*win,TotalPatNum], np.float32)
for i in range(win):
for j in range(win):
patch = img[:,i:endw-win+i+1:stride,j:endh-win+j+1:stride]
Y[:,k,:] = np.array(patch[:]).reshape(endc, TotalPatNum)
k = k + 1
return Y.reshape([endc, win, win, TotalPatNum])

def is_low_contrast(image, fraction_threshold=0.1, lower_percentile=10,
upper_percentile=90):
"""Determine if an image is low contrast."""
limits = np.percentile(image, [lower_percentile, upper_percentile])
ratio = (limits[1] - limits[0]) / limits[1]
return ratio < fraction_threshold

data_name="MSRS_train"
img_size=128 #patch size
stride=200 #patch stride

IR_files = sorted(get_img_file(r"/MSRS_train/train/ir"))
VIS_files = sorted(get_img_file(r"/MSRS_train/train/vi"))

assert len(IR_files) == len(VIS_files)

#create the directory if it doesn't exist
output_dir = os.path .join('data')
if not os.path.exists(output_dir):
os.makedirs(output_dir)

file_path = os.path.join(output_dir, data_name + 'imgsize' + str(img_size) + "stride" + str(stride) + '.h5')

h5f = h5py.File(file_path, 'w')
h5_ir = h5f.create_group('ir_patchs')
h5_vis = h5f.create_group('vis_patchs')
train_num=0

for i in tqdm(range(len(IR_files))):
I_VIS = imread(VIS_files[i]).astype(np.float32).transpose(2,0,1)/255. # [3, H, W] Uint8->float32
I_VIS = rgb2y(I_VIS) # [1, H, W] Float32
I_IR = imread(IR_files[i]).astype(np.float32)[None, :, :]/255. # [1, H, W] Float32

    # crop    
    I_IR_Patch_Group = Im2Patch(I_IR,img_size,stride)
    I_VIS_Patch_Group = Im2Patch(I_VIS, img_size, stride)  # (3, 256, 256, 12)
    
    for ii in range(I_IR_Patch_Group.shape[-1]):
        bad_IR = is_low_contrast(I_IR_Patch_Group[0,:,:,ii])
        bad_VIS = is_low_contrast(I_VIS_Patch_Group[0,:,:,ii])
        # Determine if the contrast is low
        if not (bad_IR or bad_VIS):
            avl_IR= I_IR_Patch_Group[0,:,:,ii]  #  available IR
            avl_VIS= I_VIS_Patch_Group[0,:,:,ii]
            avl_IR=avl_IR[None,...]
            avl_VIS=avl_VIS[None,...]

            h5_ir.create_dataset(str(train_num),     data=avl_IR, 
                            dtype=avl_IR.dtype,   shape=avl_IR.shape)
            h5_vis.create_dataset(str(train_num),    data=avl_VIS, 
                            dtype=avl_VIS.dtype,  shape=avl_VIS.shape)
            train_num += 1        

h5f.close()

with h5py.File(file_path,"r") as f:
for key in f.keys():
print(f[key], key, f[key].name)

@HaiyanggJiang
Copy link

Thank you bro!

@xiaozhongrui
Copy link

还是不行呀 这个下载的大小为0KB有佬来解释下吗

@YooLiuXiao
Copy link

创建data文件夹后,然后.\data相对路径改成绝对路径

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants