“”"
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 + '/' + filenameif 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()

如何把UCF101数据集分成训练集和测试集相关推荐

  1. 将数据集分为训练集和测试集(python脚本)

    文章目录 程序: 下面简单介绍一下程序流程 1.引入库 os库 shutil random 2.mk_file函数 3.主函数 程序: 我们在训练卷积神经网络之前,要搭建好数据集,分成训练集和测试集两 ...

  2. python划分数据集用pandas_用pandas划分数据集实现训练集和测试集

    1.使用model_select子模块中的train_test_split函数进行划分 数据:使用kaggle上Titanic数据集 划分方法:随机划分 # 导入pandas模块,sklearn中mo ...

  3. 【自存代码】划分数据集为训练集和测试集

    [自存代码]划分image和label为训练集和测试集 修改自这位大佬的代码:https://blog.csdn.net/weixin_47414034/article/details/1254793 ...

  4. python创建数据集_利用 python 在本地数据集创建训练集和测试集

    根据自己的数据集,自动划分训练集.测试集 举个栗子: 已经分好的文件: origin 文件夹有三类数据:good,bad,m,每类文件夹包含不同数量的图片,如下: 需要生成数据集的文件: 结果:根据设 ...

  5. iris数据集_sklearn日志(二)训练集和测试集划分

    机器学习算法需要大量的数据,这些数据一部分用于模型训练,另一部分作为测试或验证. 机器学习入坑者:sklearn日志(一)体验官方提供的标准数据集​zhuanlan.zhihu.com sklearn ...

  6. oxford5k和paris6k数据集介绍_sklearn函数:KFold(分割训练集和测试集)

    上一篇介绍了train_test_split函数: 橘猫吃不胖:sklearn函数:train_test_split(分割训练集和测试集)​zhuanlan.zhihu.com 主要场景是,我们想要将 ...

  7. 31,32,33_过拟合、欠拟合的概念、L2正则化,Pytorch过拟合欠拟合,交叉验证-Train-Val-Test划分,划分训练集和测试集,K-fold,Regularization

    1.26.过拟合.欠拟合及其解决方案 1.26.1.过拟合.欠拟合的概念 1.26.1.1.训练误差和泛化误差 1.26.1.2.验证数据集与K-fold验证 1.26.1.3.过拟合和欠拟合 1.2 ...

  8. idea2020.2中@test是怎么测试的_Sklearn 划分训练集和测试集

    [从零开始学机器学习第 03 篇] 摘要:手写 Sklearn 的 train_test_split 函数. 之前两篇文章以酒吧的红酒故事引出了 kNN 分类算法,根据已倒好的酒(样本),预测新倒的酒 ...

  9. [机器学习笔记] 将数据拆分成训练集和测试集的几种方法

    问题描述: 一般情况下, 我们习惯将原始数据中的80% 作为训练集, 20% 作为测试集(当数据量足够大的时候,也可以将10% 作为测试集. 数据量较小时,如果每次都是随机划分训练集,执行多次训练后, ...

  10. 随机切分csv训练集和测试集 鸢尾花

    import csv import os import numpy as np '''将iris.csv中的数据分成train_iris和test_iris两个csv文件,其中train_iris.c ...

最新文章

  1. 重磅!国内首个面向自动驾驶领域的多传感器数据融合系统课程
  2. 容灾备份技术的分类概述
  3. 三十二、数据库设计的三范式【完】
  4. shell脚本例子集锦
  5. Quartz简单触发
  6. 【机器学习】太棒了!8 个开源自动化机器学习框架,轻松搞定机器学习!
  7. poj-2336 Ferry Loading II(dp)
  8. Python中的Number(数字)
  9. Nginx学习笔记(五) 源码分析内存模块内存对齐
  10. 【参赛作品19】【openGauss】gsql客户端工具(二)gsql客户端工具之Data Studio客户端工具
  11. 技术可行性与操作可行性的资料搜集与分析
  12. c++ vector容器emplace_back
  13. MindSpore新工具TinyMS体验
  14. 【洛谷】P1138 第k小整数
  15. java pdf 插入图片_java在pdf模板的指定位置插入图片
  16. Git入门基础-Chivalrous-专题视频课程
  17. 2021 Google 开发者大会进行时: 汇聚开发者合力,共建全球技术生态
  18. GRBL学习-常用G代码
  19. 华为计算机视觉算法,【华为图像算法面试】计算机视觉算法岗,第一面就挂了-看准网...
  20. 电信运营商的流量经营策略与方法培训大纲

热门文章

  1. ML Mastery 博客文章翻译 20220116 更新
  2. matlab系统辨识尝试之详细过程1,系统辨识工具箱教程
  3. ldd usr bin mysql_ldd与otool
  4. 按键精灵定位坐标循环_按键精灵的控制命令居然恐怖到了这种程度
  5. ftp连接工具,8款免费又好用的ftp连接工具
  6. Solidity学习教程
  7. python实现团队游戏小程序——你画我猜
  8. 边缘计算卸载matlab仿真,移动边缘计算卸载技术简介
  9. IDEA打包普通Java web项目
  10. dnf体验服显示服务器爆满,DNF:体验服刚更新就爆满,官方临时加频道,100级真那么好玩?...