|
import json |
|
import os |
|
from utils.mama_utils import * |
|
|
|
|
|
|
|
def data_to_json(data_matrix): |
|
results = [] |
|
for row in data_matrix: |
|
result = {"person_name": row[0], |
|
"img_url": row[1], |
|
"score": row[2], |
|
"conclusion": row[3] |
|
} |
|
results.append(result) |
|
return json.dumps({"results": results}, ensure_ascii=False, indent=4) |
|
|
|
|
|
|
|
def read_json_label(json_file_path='./data/suanfamama-fashion-guangzhou-dataset/20240722_label/20240722-193429-6.json'): |
|
|
|
if not os.path.exists(json_file_path): |
|
print(f" {json_file_path}JSON不存在") |
|
return None |
|
|
|
|
|
with open(json_file_path, 'r', encoding='utf-8') as file: |
|
data = json.loads(file.read()) |
|
|
|
|
|
image_path = data['imagePath'] |
|
|
|
|
|
labels_with_boxes = [] |
|
|
|
|
|
for shape in data['shapes']: |
|
label = shape['label'] |
|
xyxy = [shape['points'][0][0], shape['points'][0][1], shape['points'][1][0], shape['points'][1][1]] |
|
labels_with_boxes.append({'label': label, 'xyxy': xyxy}) |
|
|
|
return image_path, labels_with_boxes |
|
|
|
|
|
|
|
def text_to_json(text): |
|
|
|
transform = {'人物类型': 'type', |
|
'上衣类型': 'upper_garment', |
|
'下衣类型': 'lower_garment', |
|
'帽子类型': 'headgear', |
|
'袜子类型': 'sock', |
|
'鞋子类型': 'shoe', |
|
'配饰类型': 'accessory', |
|
'背包类型': 'backpack', |
|
'动作类型': 'action', |
|
'表情类型': 'countenance' |
|
} |
|
|
|
lines = text.split('\n') |
|
data = {} |
|
for line in lines: |
|
parts = line.strip().split(':') |
|
if len(parts) < 2: |
|
continue |
|
key = transform.get(parts[0].strip()) |
|
value = parts[1].strip() |
|
if contains_any_keyword(value, ['未', '无']): |
|
value = "None" |
|
if key: |
|
data[key] = value |
|
return data |
|
|