当前位置:网站首页>深度学习训练前快速批量修改数据集中的图片名
深度学习训练前快速批量修改数据集中的图片名
2022-08-05 00:44:00 【佐咖】
深度学习训练前快速批量修改数据集中的图片名,使用下面代码时只需要修改两个路径即可,见下:

具体代码见下:
import os
class BatchRename():
''' 批量重命名文件夹中的图片文件 '''
def __init__(self):
self.path = 'Images/val/val2017' #表示需要命名处理的文件夹
self.save_path='Images/val/val2017 2'#保存重命名后的图片地址
def rename(self):
filelist = os.listdir(self.path) #获取文件路径
total_num = len(filelist) #获取文件长度(个数)
i = 1 #表示文件的命名是从1开始的
for item in filelist:
print(item)
if item.endswith('.jpg'): #初始的图片的格式为jpg格式的(或者源文件是png格式及其他格式,后面的转换格式就可以调整为自己需要的格式即可)
src = os.path.join(os.path.abspath(self.path), item)#当前文件中图片的地址
dst = os.path.join(os.path.abspath(self.save_path), ''+str(i) + '.jpg')#处理后文件的地址和名称,可以自己按照自己的要求改进
try:
os.rename(src, dst)
print ('converting %s to %s ...' % (src, dst))
i = i + 1
except:
continue
print ('total %d to rename & converted %d jpgs' % (total_num, i))
if __name__ == '__main__':
demo = BatchRename()
demo.rename()
以上就是快速批量修改数据集中图片名的方法,希望能帮助到你,谢谢!
边栏推荐
- 2022杭电多校第三场 L题 Two Permutations
- 国内网站用香港服务器会被封吗?
- Lattice PCIe 学习 1
- Software testing interview questions: What stages should a complete set of tests consist of?
- 2021年11月网络规划设计师上午题知识点(上)
- 软件测试面试题:软件测试类型都有哪些?
- oracle创建用户
- Theory of Software Fundamentals
- 2022牛客多校训练第二场 L题 Link with Level Editor I
- 《WEB安全渗透测试》(28)Burp Collaborator-dnslog外带技术
猜你喜欢

If capturable=False, state_steps should not be CUDA tensors

倒计时1天!8月2日—4日与你聊聊开源与就业那些事!

After the staged testing is complete, have you performed defect analysis?

Theory of Software Fundamentals

Kubernetes 网络入门

TinyMCE禁用转义

gorm joint table query - actual combat

【FreeRTOS】FreeRTOS与stm32内置堆栈的占用情况

oracle创建表空间

oracle create tablespace
随机推荐
leetcode:267. 回文排列 II
B站7月榜单丨飞瓜数据B站UP主排行榜发布!
2022 Hangzhou Electric Multi-School Training Session 3 1009 Package Delivery
Software Testing Interview Questions: Qualifying Criteria for Software Acceptance Testing?
D - I Hate Non-integer Number (count of selected number dp
软件测试面试题:软件测试类型都有哪些?
创意代码表白
软件测试面试题:请你分别画出 OSI 的七层网络结构图和 TCP/IP 的四层结构图?
matlab 采用描点法进行数据模拟和仿真
2022 Hangzhou Electric Power Multi-School Session 3 Question B Boss Rush
软件测试面试题:做好测试计划的关键是什么?
2022杭电多校第三场 K题 Taxi
软件测试面试题:负载测试、容量测试、强度测试的区别?
oracle create user
Countdown to 1 day!From August 2nd to 4th, I will talk with you about open source and employment!
E - Many Operations (按位考虑 + dp思想记录操作后的结果
JUC线程池(一): FutureTask使用
2022 Nioke Multi-School Training Session 2 J Question Link with Arithmetic Progression
[idea] idea configures sql formatting
MongoDB搭建及基础操作