如何将训练集所有图片的路径信息写入Pandas dataframe存成HDF5文件

最近在跑一个用GAN做图片压缩的网络,训练测试验证集的信息都需要封装成HDF5文件,因此记录一下供自己参考。我需要训练自己的数据集,因此要写一个新的HDF5。

工程的指导上写的是:

In each case, you will need to create a Pandas dataframe containing a single column: path, which holds the absolute/relative path to the images. This should be saved as a HDF5 file。

打印了一下已有的cityscapes_paths_test.h5,显示如下:

因为我加了语义的mask,打算使用cGAN,所以需要再加一列语义的label路径。(You will need to download the gtFine dataset of annotation maps and append a separate column semantic_map_paths to the Pandas dataframe pointing to the corresponding images from the gtFine dataset.)

代码如下:

import glob
import os
import pandas as pd

img_path = ''   #图片路径
map_path = ''   #语义label路径

i_paths = glob.glob(os.path.join(img_path,'*.png'))
i_paths.sort()
map_paths = glob.glob(os.path.join(map_path,'*.png'))
map_paths.sort()
d = {'semantic_map_paths': map_paths}
df = pd.DataFrame(data=d)  #生成dataframe
df.insert(0,'path',i_paths) #加入一列
#print(df)
df.to_hdf('kitti_paths_train.h5', key='test') #转存为h5文件

然后读取看看格式:

f = pd.read_hdf('kitti_paths_train.h5')
print(f)

封装成功。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值