pycharm-创建xxxx.py文件的时候自动生成文件头部的注释(FileName、Author、Time...)

在PyCharm中,通过File > Settings,进入Editor的File and Code Templates,选择Files > Python Script,可以自定义Python文件的模板内容。新建Python文件时,会应用此模板,方便快速启动新项目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、进入pycharm 》选中File 》选中Settings

2、选中Editor 》选中 File and Code Templates 》Files 》Python Script:然后填写如下内容。

 

3、创建xxxx.py文件,效果图如下

 

 

 

 

 

 

# -*- encoding: utf-8 -*- """ @File : demo.py @Time : 2020/1/1 00:00 @Author : XXX @Email : XXXX@fitow-alpha.com @Software: PyCharm # Copyright 2020 The Fitow Authors. All Rights Reserved. 将各路径下的project文件转成coco,会找到给定路径下的所有project,且project需与图片在同一路径下 """ import os import json from PIL import Image def split_to_yolo(single_project): via_project = json.load(open(single_project, 'rb')) save_path = os.path.split(single_project)[0] via_img_metadata = via_project["_via_img_metadata"] super_category = list(via_project["_via_attributes"]["region"].keys())[0] labels = list(list(via_project["_via_attributes"]["region"].values())[0]["options"].keys()) for key, single_img_inf in via_img_metadata.items(): file_name = single_img_inf["filename"] regions = single_img_inf["regions"] im = Image.open(os.path.join(save_path, file_name), 'r') ann_info_dic = "" export_file = os.path.join(save_path, file_name[:-4] + ".txt") if regions != []: # print(file_name) for single_label_inf in regions: label_index = labels.index(single_label_inf["region_attributes"][super_category]) label_left_x = single_label_inf["shape_attributes"]["x"] label_left_y = single_label_inf["shape_attributes"]["y"] label_w = single_label_inf["shape_attributes"]["width"] label_h = single_label_inf["shape_attributes"]["height"] #将边框规范到图内 if label_left_x < 0: label_left_x = 0 if label_left_y < 0: label_left_y = 0 if label_w > im.width: label_w = im.widt if label_h > im.height: label_h = im.height ann_info_dic = str(label_index) \ + ' ' + str((label_left_x + label_w / 2) / im.width) \ + ' ' + str((label_left_y + label_h / 2) / im.height) \ + ' ' + str(label_w / im.width) \ + ' ' + str(label_h / im.height) \ + '\n' with open(export_file, "a+") as out_file: out_file.write(ann_info_dic) else: with open(export_file, "a+") as out_file: out_file.write(ann_info_dic) def project_to_yolo(input_dir_list): project_path_list = [] for single_path in input_dir_list: for root, dirs, files in os.walk(single_path): for name in files: if 'project' in name: project_path_list.append(os.path.join(root, name)) for single_project in project_path_list: print(single_project) split_to_yolo(single_project) print("over") if __name__ == "__main__": input_dir_list = [r'D:\code\yolov5-6.0\banshita'] #input_dir_list = [r'E:/公司文件/valimages'] project_to_yolo(input_dir_list)
最新发布
03-23
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值