当前位置:网站首页>深度学习训练前快速批量修改数据集中的图片名
深度学习训练前快速批量修改数据集中的图片名
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()
以上就是快速批量修改数据集中图片名的方法,希望能帮助到你,谢谢!
边栏推荐
- 软件测试面试题:BIOS, Fat, IDE, Sata, SCSI, Ntfs windows NT?
- 2022杭电多校 第三场 B题 Boss Rush
- Matlab uses plotting method for data simulation and simulation
- 软件测试面试题:黑盒测试、白盒测试以及单元测试、集成测试、系统测试、验收测试的区别与联系?
- leetcode:266. 回文全排列
- Software Testing Interview Questions: Qualifying Criteria for Software Acceptance Testing?
- ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionExcep
- leetcode:269. 火星词典
- Will domestic websites use Hong Kong servers be blocked?
- 【FreeRTOS】FreeRTOS与stm32内置堆栈的占用情况
猜你喜欢
QSunSync Qiniu cloud file synchronization tool, batch upload
【idea】idea配置sql格式化
倒计时1天!8月2日—4日与你聊聊开源与就业那些事!
MongoDB construction and basic operations
[230] Execute command error after connecting to Redis MISCONF Redis is configured to save RDB snapshots
node uses redis
Will domestic websites use Hong Kong servers be blocked?
金九银十面试跳槽季;你准备好了吗?
ora-01105 ora-03175
ORA-01105 ORA-03175
随机推荐
tiup uninstall
tiup update
TinyMCE禁用转义
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
2022 Multi-school Second Session K Question Link with Bracket Sequence I
oracle create tablespace
JUC thread pool (1): FutureTask use
Software testing interview questions: the difference and connection between black box testing, white box testing, and unit testing, integration testing, system testing, and acceptance testing?
软件测试面试题:负载测试、容量测试、强度测试的区别?
If capturable=False, state_steps should not be CUDA tensors
More than 2022 cattle school training topic Link with the second L Level Editor I
进程间通信和线程间通信
2022杭电多校 第三场 B题 Boss Rush
Binary tree [full solution] (C language)
E - Distance Sequence (prefix and optimized dp
创意代码表白
2022 Nioke Multi-School Training Session 2 J Question Link with Arithmetic Progression
After the staged testing is complete, have you performed defect analysis?
About I double-checked and reviewed the About staff page, returning an industry question
"No title"