File size: 4,453 Bytes
c741073 4e7c6f0 c741073 4e7c6f0 c741073 4e7c6f0 c741073 3292e39 f95e5c4 ddc2b54 3292e39 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
---
dataset_info:
features:
- name: images
sequence: string
- name: messages
list:
- name: content
list:
- name: index
dtype: int64
- name: text
dtype: string
- name: type
dtype: string
- name: role
dtype: string
splits:
- name: train
num_bytes: 441616494
num_examples: 10000
download_size: 549306
dataset_size: 441616494
configs:
- config_name: default
data_files:
- split: train
path: data/train-*
---
여기서 image 는 [hubble ultra deep field](https://esahubble.org/images/heic0611b/) 를 사용하면 편합니다.
[publication JPEG](https://cdn.esahubble.org/archives/images/publicationjpg/heic0611b.jpg) 를 받으시면 4000x4000 사이즈 입니다.
참고 : 4000x4000/(28x28)=~20408
업로드에 사용한 코드
```python
import json
import copy
from datasets import Dataset
from huggingface_hub import login
def create_huggingface_dataset(num_entities=10000):
# 긴 텍스트 생성을 위한 함수
def generate_long_text():
long_text = ""
for char in "abcdefghijk": # a부터 k까지
for i in range(1000): # 000부터 999까지
long_text += f"{char}{i:03d}" # 예: a000, a001, ..., k999
return long_text
# 공통으로 사용할 긴 텍스트 생성 (메모리 효율성을 위해)
long_text = generate_long_text()
# 이미지 경로 설정 - 이제 각 엔티티마다 이미지 경로 리스트 생성
image_path = "./large_image_for_debug.jpg"
# 데이터셋 구조 생성을 위한 빈 리스트
images_list = []
messages_list = []
# 10,000개의 동일한 entity 생성
for i in range(num_entities):
# 각 엔티티마다 이미지 경로 리스트 추가 (1개의 이미지 포함)
images_list.append([image_path]) # 리스트로 감싸서 추가
# 메시지 생성
message = [
{
"role": "user",
"content": [
{
"type": "image",
"index": 0,
"text": None
},
{
"type": "text",
"index": None,
"text": f"Write a000 to k999 (Entity {i+1})"
}
]
},
{
"role": "assistant",
"content": [
{
"type": "text",
"index": None,
"text": long_text
}
]
}
]
messages_list.append(message)
# 최종 데이터셋 구조
dataset_dict = {
"images": images_list,
"messages": messages_list
}
return dataset_dict
# 허깅페이스 로그인 (API 토큰 필요)
login() # 이 부분에서 토큰을 요청하거나 환경 변수에서 가져옵니다
# 데이터셋 생성
print("데이터셋 생성 중...")
dataset_dict = create_huggingface_dataset()
# 생성된 데이터셋의 크기 확인
entity_count = len(dataset_dict["messages"])
print(f"생성된 entity 수: {entity_count}")
print(f"첫 번째 entity의 images 형식: {dataset_dict['images'][0]}") # 이미지가 리스트 형태인지 확인
# HuggingFace Dataset 객체로 변환
# 메모리 효율을 위해 청크로 나누어 처리
chunk_size = 100 # 한 번에 처리할 entity 수
dataset_chunks = []
for i in range(0, entity_count, chunk_size):
end_idx = min(i + chunk_size, entity_count)
chunk_dict = {
"images": dataset_dict["images"][i:end_idx],
"messages": dataset_dict["messages"][i:end_idx]
}
dataset_chunks.append(Dataset.from_dict(chunk_dict))
# 청크들을 하나의 데이터셋으로 결합
from datasets import concatenate_datasets
final_dataset = concatenate_datasets(dataset_chunks)
# 데이터셋의 실제 형식 확인
print("데이터셋 샘플 형식:")
print(final_dataset[0])
# 데이터셋 허브에 업로드
print("허깅페이스 허브에 데이터셋 업로드 중...")
final_dataset.push_to_hub(
"Ryoo72/long_for_debug", # 여기에 자신의 사용자 이름과 원하는 데이터셋 이름 입력
private=True # 비공개 설정 (선택사항)
)
print("데이터셋 업로드 완료!")
``` |