将数据集转为hdf5格式

安装 h5py

pip install h5py

转化hdf5格式

这里以 scene 数据集为例,该数据集可在 https://mulan.sourceforge.net/datasets-mlc.html 中获取

import h5py
from scipy.io import arff
import numpy as np

source_path = r'./scene.arff'
target_path = r'./scene.hdf5'

data, meta = arff.loadarff(source_path)
feature = []
target = []
for i in range(data.shape[0]):
	t = list(data[i])
	feature.append(t[:-6])
	target.append([int(bytes.decode(v)) for v in t[-6:]])
feature = np.array(feature)
target = np.array(target)

# 保存到 target_path
with h5py.File(target_path, 'w') as hf:
	hf.create_dataset('feature', data=feature)
	hf.create_dataset('target', data=target)
# 查看
with h5py.File(target_path, 'r') as hf:
	print('keys: ', hf.keys())
	print(hf['feature'].shape)
	print(hf['target'])

相关推荐

  1. 数据转为hdf5格式

    2024-07-18 05:24:05       23 阅读
  2. VOC2012数据格式转化为YOLO格式

    2024-07-18 05:24:05       30 阅读
  3. Ubuntu按转发HDF5

    2024-07-18 05:24:05       49 阅读
  4. golangpcm格式音频转为mp3格式

    2024-07-18 05:24:05       36 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-18 05:24:05       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-18 05:24:05       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-18 05:24:05       58 阅读
  4. Python语言-面向对象

    2024-07-18 05:24:05       69 阅读

热门阅读

  1. 【大模型】如何书写好的prompt

    2024-07-18 05:24:05       21 阅读
  2. 设计模式大白话之装饰者模式

    2024-07-18 05:24:05       19 阅读
  3. 8个步骤彻底清理Docker镜像

    2024-07-18 05:24:05       27 阅读
  4. C#调用非托管dll,并从dll中再调用C#中的方法

    2024-07-18 05:24:05       23 阅读
  5. tomcat日志与log4j日志保留最近7天

    2024-07-18 05:24:05       23 阅读
  6. 一次超时导致的协程泄露

    2024-07-18 05:24:05       20 阅读
  7. day7 错误恢复(Panic Recover)

    2024-07-18 05:24:05       16 阅读
  8. c++邻接表

    2024-07-18 05:24:05       19 阅读
  9. Swift 数据类型

    2024-07-18 05:24:05       22 阅读