find bug import json Replace 'yourfile.json' with the actual file path with…
- User
find bug import json
Replace 'your_file.json' with the actual file path
with open('G:\style ai\dataset.json', 'r', encoding='utf-8') as f: data = json.load(f)
files = []
for i in data['Entries']: for e in i['f']: files.append(e)
def sort_and_group_by_first_symbol(data): """Sorts strings by first symbol and groups them in a dictionary.""" groups = {item[0]: [] for item in data} # Create dictionary with first symbols as keys for item in data: groups[item[0]].append(item) # Append strings to their corresponding groups return groups
import os import json import torch
result_tensors = {}
dir = "H:/gelbooru_all/embeddings/" for key, items in sort_and_group_by_first_symbol(files).items(): print(key) result = {} paths = torch.load(dir + f'{key}_path.pt') tensors = torch.load(dir + f'{key}_tensor.pt') paths_indexes = {string: index for index, string in enumerate(paths)} for path in items: base, extension = os.path.splitext(path) index = paths_indexes[base] tensor = tensors[index] result_tensors[path] = tensor
def get_tensors(paths): tensors = [result_tensors[path] for path in paths] return torch.stack(tensors)
for i in data['Entries']: i['f'] = get_tensors(i['f']) torch.save(data, "G:/style ai/dataset.pth")
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.