svjack commited on
Commit
314a834
·
verified ·
1 Parent(s): f426a37

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +60 -0
README.md CHANGED
@@ -31,3 +31,63 @@ configs:
31
  - split: train
32
  path: data/train-*
33
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  - split: train
32
  path: data/train-*
33
  ---
34
+
35
+ ```python
36
+ from datasets import Dataset, load_dataset
37
+ from PIL import Image
38
+ import io
39
+
40
+ def bytes_to_image(image_bytes):
41
+ """
42
+ 将字节数据(bytes)转换为 PIL.Image 对象。
43
+ """
44
+ image_stream = io.BytesIO(image_bytes)
45
+ image = Image.open(image_stream)
46
+ return image
47
+
48
+ # 加载数据集
49
+ ds = load_dataset("svjack/OnePromptOneStory-Examples-Vid-head2")["train"]
50
+
51
+ # 定义 motion_bucket_ids
52
+ motion_bucket_ids = [10, 20, 30, 40, 50]
53
+
54
+ # 创建一个新的数据集列表
55
+ new_data = []
56
+
57
+ # 遍历原始数据集中的每一行
58
+ for example in ds:
59
+ sub_images = example["sub_images"]
60
+ videos = example["videos"]
61
+
62
+ # 遍历每个 sub_image
63
+ for idx, sub_image_dict in enumerate(sub_images):
64
+ sub_image_bytes = sub_image_dict["bytes"]
65
+ sub_image = bytes_to_image(sub_image_bytes)
66
+
67
+ # 计算对应的视频索引
68
+ video_idx = idx * len(motion_bucket_ids)
69
+
70
+ # 遍历每个 motion_bucket_id 和对应的视频
71
+ for i, motion_bucket_id in enumerate(motion_bucket_ids):
72
+ video_dict = videos[video_idx + i]
73
+ video_bytes = video_dict["video_bytes"] # 视频的二进制数据
74
+
75
+ # 创建新的样本,保留原始数据的所有字段
76
+ new_sample = {
77
+ **example, # 保留原始数据的所有字段
78
+ "sub_image": sub_image,
79
+ "motion_bucket_id": motion_bucket_id,
80
+ "video": video_bytes # 直接存储视频的二进制数据
81
+ }
82
+
83
+ # 添加到新数据集中
84
+ new_data.append(new_sample)
85
+
86
+ # 将新数据转换为 Hugging Face Dataset 对象
87
+ new_dataset = Dataset.from_list(new_data)
88
+
89
+ # 查看新数据集中的第一个样本
90
+ #print(new_dataset[0])
91
+
92
+ new_dataset.push_to_hub("svjack/OnePromptOneStory-Examples-Vid-head2-Exp")
93
+ ```