-
-
Save TakashiKusachi/def5ccd905d8047e58d10cb234efe20b to your computer and use it in GitHub Desktop.
chainerのjsonログファイルをcsv形式に変換する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| python chainer_log_to_csv.py [input path] [output path] | |
| """ | |
| import argparse | |
| import csv | |
| import json | |
| def convert(input_name,output_name): | |
| log_list = json.load(open(input_name)) | |
| csv_writer = csv.writer(open(output_name, 'w')) | |
| header_list = list(sorted(max([one.keys() for one in log_list],key=len))) | |
| csv_writer.writerow(header_list) | |
| for log in log_list: | |
| csv_writer.writerow([log[header] if header in log else None for header in header_list]) | |
| if __name__=="__main__": | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('input') | |
| parser.add_argument('output') | |
| args = parser.parse_args() | |
| convert(args.input,args.output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment