TiM-Toy-T2I-Dataset / get_sampler.py
GoodEnough's picture
Upload get_sampler.py with huggingface_hub
e2ce257 verified
raw
history blame contribute delete
887 Bytes
import math
import json
with open('bucket_categorization.json', 'r') as fp:
bucket_data = json.load(fp)
print(len(bucket_data))
base_batch_size = 16
base_context_length = 1024 * 1024
all_data = 0
sampler_meta = []
for bucket, indices in bucket_data.items():
resolution = bucket.split('x')
height, width = int(resolution[0]), int(resolution[1])
batch_size = round(base_batch_size*base_context_length/(height*width))
batch_size = min(batch_size, 128)
num_batch = round(len(indices) / batch_size)
for i in range(num_batch):
current_indices = indices[i*batch_size: (i+1)*batch_size]
if len(current_indices) == batch_size:
all_data += batch_size
sampler_meta.append(current_indices)
print(all_data)
print(len(sampler_meta))
with open('bucket_sampler.json', 'w') as fp:
json.dump(sampler_meta, fp, indent=4)