RuntimeError: Unable to create link (name already exists) when I append hdf5 file?

时光总嘲笑我的痴心妄想 提交于 2020-11-29 03:30:06

问题


I am trying to append the hdf5 dataset to the previous hdf5 dataset
following error occured

h5o.link(obj.id, self.id, name, lcpl=lcpl, lapl=self._lapl) 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/h5o.pyx", line 202, in h5py.h5o.link RuntimeError: Unable to create link (name already exists)

 sal_maps = np.array([], dtype=np.float32).reshape((0,) + img_size)
        probs = np.array([], dtype=np.float32)
        preds = np.array([], dtype=np.uint8)
        for idx, (img, target) in enumerate(dataloader):

    # TODO problem1 idx problem
            sal_maps_b, probs_b, preds_b = self.generate_image(img, idx)
            sal_maps_b = np.transpose(sal_maps_b, axes=(3,0, 1, 2))

            sal_maps = np.vstack([sal_maps,sal_maps_b])
            probs = np.append(probs, probs_b)
            preds = np.append(preds,preds_b)
            #if idx ==2: break
            if idx % 100 == 0:
                print("idx->{} sal_maps->{}, probs->{} , preds->{}".format(idx,sal_maps.shape,probs.shape,preds.shape))

        # TODO indent change

                print("result->{}".format(sal_maps.size))
                with h5py.File(self.datapath, 'a') as hf:
                    hf.create_dataset('saliencys', data=sal_maps)
                    hf.create_dataset('probs', data=probs)
                    hf.create_dataset('preds', data=preds)
                    hf.close()
                sal_maps = np.array([], dtype=np.float32).reshape((0,) + img_size)
                probs = np.array([], dtype=np.float32)
                preds = np.array([], dtype=np.uint8)
                print('Save_saliency_maps::',idx)

回答1:


  1. Go to: Miniconda3\Lib\site-packages or wherever h5py is installed.

  2. Delete h5py Folder

  3. Delete h5py-2.10.0.dist-info Folder (This might be different if you have a different 4. version).

  4. Install h5py again.

    It worked for me after a long search. Finally, I tried to delete it manually and reinstall it. IT WORKED!!!!!

By uninstalling them using cmd, pip, anaconda Some files might stuck and will cause errors even after installing a different version.



来源:https://stackoverflow.com/questions/59187054/runtimeerror-unable-to-create-link-name-already-exists-when-i-append-hdf5-fil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!