형식

{
  "imageGcsUri": "gs://bucket/filename.ext",
  "classificationAnnotation": {
    "displayName": "LABEL",
    "annotationResourceLabels": {
        "aiplatform.googleapis.com/annotation_set_name": "displayName",
        "env": "prod"
      }
   },
  "dataItemResourceLabels": {
    "aiplatform.googleapis.com/ml_use": "training/test/validation"
  }
}

이형식으로 데이터세트 만들때 집어넣어야 불러올수있음.

import json
import random
from google.cloud import storage

# 환경 설정 및 변수 정의
bucket_name = 'skin_level'
labels = ["Mild", "Medium", "Severe"]
output_jsonl_path = 'skin_level_data'  # 여기에 원하는 저장 경로를 입력하세요

class_data_ratio = {
    "Mild": {"training": 0.7, "validation": 0.15, "test": 0.15},
    "Medium": {"training": 0.7, "validation": 0.15, "test": 0.15},
    "Severe": {"training": 0.7, "validation": 0.15, "test": 0.15},
}

client = storage.Client()
bucket = client.get_bucket(bucket_name)

# JSONL 파일 생성
with open(output_jsonl_path, 'w') as jsonl_file:
    for label in labels:
        # 해당 레이블의 폴더 내의 이미지를 탐색합니다.
        blobs = bucket.list_blobs(prefix=f"dataset/{label}/")
        for blob in blobs:
            image_url = f"gs://{bucket_name}/{blob.name}"

            # 데이터 분배 비율에 따라 ml_use 값 선택
            ml_use = random.choices(
                list(class_data_ratio[label].keys()),
                weights=list(class_data_ratio[label].values())
            )[0]

            # JSONL 형식 데이터 생성
            image_info = {
                "imageGcsUri": image_url,
                "classificationAnnotation": {
                    "displayName": label,
                    "annotationResourceLabels": {
                        "aiplatform.googleapis.com/annotation_set_name": label,
                        "env": "prod"
                    }
                },
                "dataItemResourceLabels": {
                    "aiplatform.googleapis.com/ml_use": ml_use
                }
            }
            
            # JSONL 형식 문자열로 작성하여 파일에 기록
            jsonl_file.write(json.dumps(image_info) + '\\n')

print("JSONL file creation completed.")

jsonl데이터 bucket에 넣기.

gsutil cp skin_last.jsonl gs://skin_level/datasets