如何把UCF101数据集分成训练集和测试集

2023-05-16

“”"
After extracting the RAR, we run this to move all the files into
the appropriate train/test folders.

Should only run this file once!
“”"
import os
from os.path import exists
import shutil
from pathlib import Path

def get_train_test_lists(version=‘01’):
“”"
Using one of the train/test files (01, 02, or 03), get the filename
breakdowns we’ll later use to move everything.
“”"
# Get our files based on version.
test_file = os.path.join(‘ucfTrainTestlist’, ‘testlist’ + version + ‘.txt’)
# print(‘test_file路径:’,test_file)
train_file = os.path.join(‘ucfTrainTestlist’, ‘trainlist’ + version + ‘.txt’)
# print(‘train_file路径:’,train_file)

# Build the test list.
with open(test_file) as fin:
    test_list = [row.strip() for row in list(fin)]

# Build the train list. Extra step to remove the class index.
with open(train_file) as fin:
    train_list = [row.strip() for row in list(fin)]
    train_list = [row.split(' ')[0] for row in train_list]

# Set the groups in a dictionary.
file_groups = {
    'train': train_list,
    'test': test_list
}

return file_groups

def move_files(file_groups):
“”“This assumes all of our files are currently in this directory.
So move them to the appropriate spot. Only needs to happen once.
“””
# Do each of our groups.
for group, videos in file_groups.items():

    # Do each of our videos.
    for video in videos:

        # print('video:',video)
        # Get the parts.
        # parts = video.split(os.path.sep)
        parts = os.path.split(video)

        # print('不完整路径:',parts)
        classname = parts[0]
        # print('动作分类文件夹:'+classname)
        absolutepathname = ('D:/expressionDatabase/UCF101/')
        # print('绝对路径:',absolutepathname)
        filename = parts[1]
        print('文件名:' + filename)
        # print('源代码中要产生的路径是:',os.path.join(group, filename))
        # Check if this class exists.
        '''
        if not os.path.exists(os.path.join(group, filename)):
            print("Creating folder for %s/%s" % (group, filename))
            os.makedirs(os.path.join(group, filename))
        '''

        # os.path <module 'ntpath' from 'D:\\python37\\lib\\ntpath.py'>

        if not exists(absolutepathname + group + '/' + classname):
            # print("新建文件夹:", (absolutepathname + group+ '/' + classname))
            os.makedirs(absolutepathname + group + '/' + classname)

        # Check if we have already moved this file, or at least that it
        # exists to move.
        file_to_move = absolutepathname + 'UCF101/' + classname + '/' + filename
        if not os.path.exists(file_to_move):
            print("找不到要移动的文件.")
            continue

        # Move it.
        dest = Path(absolutepathname + group + '/' + classname + '/' + filename)
        print('目标路径:', dest)
        # os.rename(filename, dest)
        shutil.move(file_to_move, dest)
        print('move finished...')

print("Done.")

def main():
“”"
Go through each of our train/test text files and move the videos
to the right place.
“”"
# Get the videos in groups so we can move them.
group_lists = get_train_test_lists()
print(group_lists)
# Move the files.
move_files(group_lists)

if name == ‘main’:
main()

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

如何把UCF101数据集分成训练集和测试集 的相关文章

随机推荐

  • 【Yolo】YoloV5训练自定义模型

    Yolo Jetson Orin Nano下部署 YoloV5 上一篇博文主要记录了在Jetson Orin Nano下部署YoloV5环境 xff0c 并运行了yoloV5n pt模型 xff0c 本篇在上一篇的基础上 xff0c 进一步
  • ModSim基本使用(Modbus模拟器)

    ModSim下载地址 打开软件 1 模拟modbus tcp 创建Modbus TCP连接 设置连接端口 xff0c 默认502 xff0c 点击 OK 就自动创建 新建 新建界面如下 xff08 可新建多个界面 xff0c 同时模拟500
  • [java]final关键字的几种用法

    在java的关键字中 xff0c static和final是两个我们必须掌握的关键字 不同于其他关键字 xff0c 他们都有多种用法 xff0c 而且在一定环境下使用 xff0c 可以提高程序的运行性能 xff0c 优化程序的结构 下面我们
  • Ubuntu系统安装分区设置

    1 创建主分区 xff1a 主分区 xff0c 用于存放系统 20G 主分区 空间起始位置 Ext4日志文件系统 2 创建swap分区 xff1a 逻辑分区 大小设置为电脑内存大小 xff0c 2G xff1b 2048MB 逻辑分区 空间
  • 重装Win+Ubuntu双系统中的Ubuntu

    重装双系统中的Ubuntu 想把玩Linux xff0c 又想保留Windows xff0c 有几种途径 1 使用虚拟机软件如 Vmware Virtual Box等 2 再装一个Ubuntu系统成为Win 43 Ubuntu双系统 专业原
  • ROS打不开gazebo的问题

    前段时间 xff0c 将师兄的Ros工程搬到我的电脑上运行 xff0c 但是一直打不开gazebo xff0c gazebo一直卡在了黑屏的页面 同样的工程 xff0c 在师兄电脑上是可以跑的 xff0c 并不是ros工程的问题 于是我让其
  • 02 四旋翼无人机的组成与拼装(上)

    02 四旋翼无人机的组成与拼装 xff08 上 xff09 目录1 总体介绍2 布局设计2 1 机身布局2 1 1 交叉形2 1 2 环形 比较少2 1 3 可折叠交叉形 2 2 旋翼安装2 2 1 常规布局 VS 共轴双桨2 2 2 力矩
  • 03 四旋翼无人机的组成与拼装(下)

    03 四旋翼无人机的组成与拼装 xff08 下 xff09 目录1 螺旋桨1 1 作用1 2 参数1 型号2 弦长3 转动惯量 重要 4 力效5 桨叶数6 安全转速7 静平衡与动平衡 2 电机2 1 作用2 2 工作原理2 2 1 相位切换
  • 05 无人机动态模型

    05 无人机动态模型 目录1 无人机动态模型简介1 1 无人机动态模型2 刚体运动与姿态表示2 1 如何描述一个刚体2 2 地球坐标系与机体坐标系2 3 坐标系旋转与向量旋转的区别2 4 旋转轴与旋转角2 5 欧拉角 xff08 1 xff
  • 06 飞行控制器

    06 飞行控制器 目录1 XTDrone动态模型代码讲解2 自动控制初步2 1 自动控制概述多旋翼飞行器控制实例 2 2 控制性能2 3 传递函数与状态方程示例 3 PID控制器3 1 PID控制器3 2 比例项调节3 3 积分项调节积分饱
  • Django-注册用户时候保存密码加密问题

    1 导入django内置模块 注册用户时候保存密码加密问题 from django contrib auth hashers import make password 2 获取post参数并创建用户并对密码加密 email 61 reque
  • FrankMocap

    FrankMocap 摘要介绍相关工作3D参数化人体模型单图像3D人体姿势估计单图像3D手姿势估计身体和手的联合3D姿势估计 方法SMPL X模型概述3D手估计模块手模块结构训练方法数据集预处理训练数据增强 3D身体估计模块整个身体集成模块
  • TortoiseGit间接处理linux目录下的仓库,用到window映射linux目录方案

    原始需求 习惯用TortoiseGit查看git仓库信息和历史日志 xff0c 但这个工具只支持window xff0c 我希望linux也能用虽然有其他linux的GUI的git工具 xff0c 但我用到的linux基本都是无界面版本 x
  • 关于C中的Int类型到底是几个字节。

    C语言标准是这样规定的 xff1a int最少16位 xff08 2字节 xff09 xff0c long不能比int短 xff0c short不能比int长 xff0c 具体位长由编译器开发商根据各种情况自己决定 在32位x86处理器上
  • Jetson TX2开启高功耗模式

    Jetson TX2 工作模式及相应的CPU和GPU频率 xff1a 上电的时候 xff0c 默认最低功耗模式1 xff0c 风扇不转 1 直接运行home下的jetson clocks sh xff0c 开启最大频率 sudo jetso
  • 在失望中重找希望——我的2013年工作总结

    时间过的真的是快 来广州已整整工作了一年啦 从2012年长沙工作离职后 为了我的女朋友 我毅然踏上了南下广州的征途 来到羊城后 很快 xff0c 一个礼拜就找到了现在工作的这家公司 现在回想一下 真觉得当初没有好好斟酌一下 2013年里 x
  • 【100%有效】解决AndroidStudio 控制台编译输出中文乱码,亲测解决!

    背景 在AndroidStudio中新建了一个Java Module xff0c 但是点击 Run app 之后 xff0c Build Output 控制台输出的中文都是乱码 xff0c 都是问号一样的字符 google了很多方法 xff
  • 图传数传模块

    文章中写了关于如何调摄像头的程序 https blog csdn net JanKin BY article details 103929781 如何将摄像头获取的视频发送到远端实现图传数传 xff0c 按RJ45的网口线路排布 xff0c
  • TX2系统烧录jetpack4.6 ubuntu18.04

    sdk版本与系统版本相关 xff0c 下载的4 6为ubuntu 18 04 1 烧录下jeston nvidia官方网站上下载sdk manager Jetson 下载中心 NVIDIA Developer sudo apt instal
  • 如何把UCF101数据集分成训练集和测试集

    34 After extracting the RAR we run this to move all the files into the appropriate train test folders Should only run th