# -*- coding:utf-8 -*- import os, sys, shutil, json import os.path as osp import pandas as pd import logging from csv import DictReader import numpy as np cluster_json = '/Users/huhao/Downloads/test509/ClusterLabel.json' outfile_path = '/Users/huhao/Downloads/test509/' def parse_clusterlabel_result(cluster_json, outfile_path): try: cluster = json.load(open(cluster_json, 'r')) except FileNotFoundError as err: logging.error(err) return None if len(cluster['jobs']) > 0: with open(osp.join(outfile_path, 'cluster.csv'), 'w') as f: f.write('img,clusterid\n') for i, job in enumerate(cluster['jobs']):#以cluster进行遍历 clusterid = job['name'] for j, group in enumerate(job['clusters']):#以cluster进行遍历 for img in group['image_names']: f.write(
利用json文件将文件夹的图片分类
最新推荐文章于 2022-08-11 11:03:44 发布