#!/usr/bin/env python3
-- coding: utf-8 --
“”"
Created on Tue Jul 2 14:40:38 2019
@author: shawn
“”"
import h5py
import glob
import os
import os.path as osp
import numpy as np
dir_path = “…/DT4”
#all_image_path#
img_paths = []
pid_container = set()
for label in os.listdir(dir_path):
path = osp.join(dir_path, label,’’, '.jpg’)
img_paths.extend(glob.glob(path))
dataset = []
for img_path in img_paths:
dataset.append(img_path)
a = 1
for i in dataset:
a = a+1
imgData = np.zeros((30,a,128,256))
f = h5py.File(’…’+i.strip(os.path.basename(i)) + ‘gl_’ + os.path.basename(i).strip(’.jpg’) + ‘.h5’ ,‘w’)
f[‘data’] = imgData #将数据写入文件的主键data下面
f.close() #关闭文件
b=[]
for i in dataset:
f = h5py.File(’…’+i.strip(os.path.basename(i)) + ‘gl_’ + os.path.basename(i).strip(’.jpg’) + ‘.h5’,‘r’) #打开h5文件
f.keys() #可以查看所有的主键
a = f[‘data’][:] #取出主键为data的所有的键值
b.append(a)