我今天在用python写入hdf5的时候,出现了下面的错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-4a984659912f> in <module>()
      5 number_of_features = len(image_feature_files)
      6 for image_arg, image_file in tqdm(enumerate(image_feature_files)):
----> 7     file_id = dataset_file.create_group(image_file)
      8     image_data = file_id.create_dataset('image_features',
      9                                         (IMG_FEATS,), dtype='float32')
~/anaconda3/lib/python3.6/site-packages/h5py/_hl/group.py in create_group(self, name)
     48         with phil:
     49             name, lcpl = self._e(name, lcpl=True)
---> 50             gid = h5g.create(self.id, name, lcpl=lcpl)
     51             return Group(gid)
h5py/_objects.pyx in h5py._objects.with_phil.wrapper()
h5py/_objects.pyx in h5py._objects.with_phil.wrapper()
h5py/h5g.pyx in h5py.h5g.create()
ValueError: Not a location (invalid object ID)

然后百度没有搜到答案,我这里弥补一下空缺,错误虽小,但是出现了总会让人头疼。

我的代码为:

print('Writing image features to h5...')
IMG_FEATS = 2048
cnn_extractor='inception'
dataset_file = h5py.File(cnn_extractor +'_image_name_to_features.h5')
number_of_features = len(image_feature_files)
for image_arg, image_file in tqdm(enumerate(image_feature_files)):
    file_id = dataset_file.create_group(image_file)
    image_data = file_id.create_dataset('image_features',
                                        (IMG_FEATS,), dtype='float32')
    image_data[:] = extracted_features[image_arg,:]
    dataset_file.close()

后面发现是因为我在写入h5的时候,迭代的时候close了,所以改的方式就是把close代码放到循环外了哈

print('Writing image features to h5...')
IMG_FEATS = 2048
cnn_extractor='inception'
dataset_file = h5py.File(cnn_extractor +'_image_name_to_features.h5')
number_of_features = len(image_feature_files)
for image_arg, image_file in tqdm(enumerate(image_feature_files)):
    file_id = dataset_file.create_group(image_file)
    image_data = file_id.create_dataset('image_features',
                                        (IMG_FEATS,), dtype='float32')
    image_data[:] = extracted_features[image_arg,:]
dataset_file.close()

[1].“ValueError: Not a location id (Invalid object id)” while creating HDF5 datasets. https://stackoverflow.com/questions/49151057/valueerror-not-a-location-id-invalid-object-id-while-creating-hdf5-datasets?rq=1

我今天在用python写入hdf5的时候,出现了下面的错误:---------------------------------------------------------------------------ValueError Traceback (most recent call last)&amp;lt;ipython-inp... 复制代码 代码如下: totalCount = ‘100’ totalPage = int(totalCount)/20 ValueError : invalid literal for int() with base 10的错误 网上同样的错误有人建议用round(float(“1.0″)),但是解决不了我这个问题,round(float(“1.0″))是用于解决浮点数转换为整形数的, 而我这个则是因为原字符串转换为整形后做除法,虽然一段时间内可能不报错,但时间久了就会提示(其实就是一个warning,但是会强制终止你的程序),正确
我在练习mongodb命令的时候,这段怎么也无法通过,一直报错: Syntax Error : id entifier starts immediately after numeric literal db.mycol.insertMany([{ _ id : Object Id (7df78ad8902c) title: 'MongoDB Overview', description...
Open up .exe eclipse file from command promtp followed by command -vmargs -Djava.net.preferIPv4Stack=true changed in eclipse.init file.
近期特别欢迎国内外头部出版社尽快私信博主!——心比天高,仗剑走天涯,保持热爱,奔赴向梦想!低调,谦虚,自律,反思,成长,还算是比较正能量的博主,公益免费传播……内心特别想在AI界做出一些可以推进历史进程影响力的东西(兴趣使然,有点小情怀,也有点使命感呀)… 04-12
在使用golang实现OAuth2授权码方式时,报错:( error ) ERR Protocol error : invalid bulk length 。经逐步排查,并借助Redis Monitor命令,发现是redis使用出现了问题,报错指令格式为hmset a a1 "" a2 "hello",因value为空导致报错。 代码在本地测试时,连接的是本地的redis,localhost:6379,当执行hmset a a1 "" a2 "hello",不会报错,可正常写入redis; 代码部署后,连接的是r
Syntax Error 1. invalid syntax常是丢冒号,丢括号等问题。UnicodeDecode Error :1. 'gbk' codec can't decode byte代码如下:with open('acl-metadata.txt','r') as data:   print(data.readlines(),'\n')报错: UnicodeDecode Error : 'gbk...