python 文件操作记录

2023-05-16

#!/usr/bin/env python
# coding=utf-8

import os
import shutil

def getimagepath(path):
    file=open(path)
    data=file.read()
    lines=data.replace(',',' ').replace('\t',' ').split('\n')
    lines=[[ v.strip() for v in line.split(' ') if v.strip()!=''] for line in lines if len(line)>0 and line[0]!='#']
    res=[line[0] for line in lines if line[1]=='1']
    return res




cwd=os.getcwd()
print cwd

txtpath=cwd+'/ImageSets/Main/'
print txtpath

txtlist=os.listdir(txtpath)
namelist=[]
#print txtlist
for name in txtlist:
    index=name.find('_')
    if index!=-1:
        namelist.append(name[:index])
namelist=list(set(namelist))
print len(namelist),'\n',namelist

newfolds=cwd+'/VOC'
oldfolds=cwd+'/JPEGImages'
if not os.path.exists(newfolds):
    os.mkdir(newfolds)

datasets=['train','trainval','val']
for ds in datasets:
    if not os.path.exists(newfolds+'/'+ds):
        os.mkdir(newfolds+'/'+ds)
    for name in namelist:
        if not os.path.exists(newfolds+'/'+ds+'/'+name):
            os.mkdir(newfolds+'/'+ds+'/'+name)
        train_imagepath=getimagepath(txtpath+'/'+name+'_'+ds+'.txt')
        if len(train_imagepath)<=0:  
            print "error in getimagepath ",txtpath+'/'+name+'_'+ds+'.txt'
            exit(0)
        for image in train_imagepath:
            shutil.copyfile(oldfolds+'/'+image+'.jpg',newfolds+'/'+ds+'/'+name+'/'+image+'.jpg')






















 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

python 文件操作记录 的相关文章

随机推荐

  • manjaro VNC Viewer报错:vncviewer: error while loading shared libraries: libcrypt.so.1

    想在 manjaro 装 VNC Viewer 连实验室的 windows 主机 windows 机装 VNC Server xff0c manjaro 装 VNC Viewer 安装过程参考 1 xff0c 就下载 解压 运行里面的 vn
  • taokeeper 架设与部署

    相关下载 xff1a taokeeper sql http down 51cto com data 718756 taokeeper monitor config properties http down 51cto com data 71
  • 密钥“externalConsole”已弃用。请改用“console”。

    参考 xff1a 密钥externalConsole已弃用 请改用 console 我该怎么处理 编程语言 CSDN问答 感谢大佬jsfnzyj 解决方法 xff1a 将launch json里的cppvsdbg中原来的 34 extern
  • virtualbox 5.2.0 ,debian9 安装超详细过程,看一次就懂

    实验环境 xff1a 虚拟机 xff1a virtualbox version 5 2 0 r118431 QT5 6 2 镜像文件 xff1a debian 9 2 1 amd64 DVD 1 iso gt 选择这个完整镜像的原因是因为可
  • you-get库——python详解

    目录 part1 xff1a you get安装 part2 xff1a 使用you get part1 xff1a you get安装 输入 xff1a pip3 install you get 只基于python3 X 安装图如下 xf
  • 结构体数组的用法小结

    原文章链接 xff08 写的相当详细 xff09 http span class token operator span span class token operator span span class token operator sp
  • C++ 快读两种方法

    法一 T宝法 xff1a ios span class token double colon punctuation span span class token function sync with stdio span span clas
  • python小程序之七段数码管的绘制

    今天我们学习了七段数码管的绘制 xff0c 通过一个程序学习了数字用七段数码的绘制 首先我们看下图的绘制 xff0c 我们先理解下各个数字由几步线条组成 然后回到我们的程序 xff0c 先给大家看看我们的程序图 xff0c 因为小编录屏很模
  • 深入理解并查集(Disjoint Set Union),并利用其解决相关问题

    一 什么是并查集 xff1f 首先字面意思是把相互联系的元素通过特定查询组成一个集合 规范化解释 xff1a 并查集 xff0c 在一些有N个元素的集合应用问题中 xff0c 我们通常是在开始时让每个元素构成一个单元素的集合 xff0c 然
  • 搜索算法之迷宫问题

    迷宫问题 Description 给定一个n m方格的迷宫 xff0c 迷宫里有t处障碍 xff0c 障碍处不可通过 给定起点坐标和终点坐标 xff0c 问每个方格最多经过1次 xff0c 在迷宫中移动有上下左右四种方式 xff0c 保证起
  • TX1/2 linux 设置交换空间 记录

    TX1等当内存不足时会出现 internal compile error 设置交换空间 free m 查看内存 sudo mkdir swap cd swap sudo dd if 61 dev zero of 61 swap bs 61
  • OpenCV with CUDA 编译安装

    cmake D CMAKE BUILD TYPE 61 DEBUG D WITH CUDA 61 ON D WITH CUBLAS 61 ON D CUDA FAST MATH 61 ON D WITH CUFFT 61 ON D WITH
  • linux 安装后无法启动 修复引导grub

    1 查看磁盘信息 xff0c 确认系统安装在那个磁盘上 sudo df lh or sudo fdisk l 2 挂载 sudo mkdir mnt ubuntu 建立挂载点 sudo mount dev sda2 mnt ubuntu 挂
  • 在Ubuntu上快速安装Qt

    只需要一句话 xff0c Qt各个部件就可以快速安装好 xff0c 不需要麻烦的到官网上下载东西 当然 xff0c 安装速度取决于你的apt源的速度 xff0c 我用的华为源 xff0c 速度达到11MB S sudo apt instal
  • Argus camera API

    1 JETPACK CAMERA API LIBARGUS Advantage Open Standard Cross Platform Low level control of camera subsystem Frame based c
  • error: undefined reference to symbol '_ZN5boost6system15system_categoryEv

    使用boost时遇到下面error xff1a cmake version 3 5 1 usr bin ld CMakeFiles RGBD dir src ros rgbd cc o undefined reference to symb
  • ROS 使用signal 终止 Node

    在终端中使用ctrl 43 c可以强制终止运行的程序 xff0c 但有时需要在终止时作一些处理 xff08 如ros shotdown free等 xff09 xff0c 可使用信号函数作退出处理 头文件 include 34 csigna
  • flann error

    error usr include flann util serialization h 18 9 error class std unordered map lt unsigned int std vector lt unsigned i
  • 3个方法解决百度网盘限速

    转载自 lt 作者 xff1a 奔跑中的奶酪 原文链接 https www runningcheese com baiduyun gt 3个方法解决百度网盘限速 xff08 2019 06 20 更新 xff09 3个方法解决百度网盘限速
  • python 文件操作记录

    usr bin env python coding 61 utf 8 import os import shutil def getimagepath path file 61 open path data 61 file read lin