当前位置:网站首页>深度学习训练前快速批量修改数据集中的图片名
深度学习训练前快速批量修改数据集中的图片名
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()
以上就是快速批量修改数据集中图片名的方法,希望能帮助到你,谢谢!
边栏推荐
- could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
- redis可视化管理软件Redis Desktop Manager2022
- 如何用 Solidity 创建一个“Hello World”智能合约
- 软件测试面试题:测试生命周期,测试过程分为几个阶段,以及各阶段的含义及使用的方法?
- 僵尸进程和孤儿进程
- GCC:屏蔽动态库之间的依赖
- TinyMCE disable escape
- 2022牛客多校训练第二场 J题 Link with Arithmetic Progression
- Software Testing Interview Questions: What do test cases usually include?
- Lattice PCIe 学习 1
猜你喜欢
随机推荐
EL定时刷新页面中的皕杰报表实例
Zombie and orphan processes
Software Testing Interview Questions: What is Software Testing?The purpose and principle of software testing?
tensor.nozero(),面具,面具
软件测试面试题:BIOS, Fat, IDE, Sata, SCSI, Ntfs windows NT?
Software Testing Interview Questions: What's the Key to a Good Test Plan?
After the staged testing is complete, have you performed defect analysis?
node uses redis
MongoDB construction and basic operations
软件测试面试题:您以往所从事的软件测试工作中,是否使用了一些工具来进行软件缺陷(Bug)的管理?如果有,请结合该工具描述软件缺陷(Bug)跟踪管理的流程?
tiup uninstall
E - Many Operations (按位考虑 + dp思想记录操作后的结果
2022 Hangzhou Electric Power Multi-School Session 3 Question L Two Permutations
软件测试面试题:系统测试的策略有?
软件测试面试题:请你分别画出 OSI 的七层网络结构图和 TCP/IP 的四层结构图?
tensor.nozero(), mask, [mask]
2022杭电多校第三场 K题 Taxi
[230] Execute command error after connecting to Redis MISCONF Redis is configured to save RDB snapshots
软件测试面试题:您如何看待软件过程改进?在您曾经工作过的企业中,是否有一些需要改进的东西呢?您期望的理想的测试人员的工作环境是怎样的?
2022牛客多校训练第二场 J题 Link with Arithmetic Progression








