LUA中将未分类数据分为测试集和训练集
require 'torch'
require 'image'
local setting = {parent_root = '/home/pxu/image'} function list_children_root(path)
local i,t,popen = ,{},io.popen
for file_name in popen('ls -a ' .. path):lines() do
i = i +
if i> then
t[i-] = file_name
--if i>0 then
--t[i] = file_name
end
end
return t
end function list_img(path)
--print(path)
local i,t,popen = ,{},io.popen
for file_name in popen('ls -a ' .. path .. ' |grep jpg'):lines() do
i = i +
t[i] = file_name
end
return t
end
print('obtain children root path ...')
train_paths,train_labels = {},{}
test_paths,test_labels = {}, {}
children_paths = list_children_root(setting.parent_root)
print(children_paths)
num_train,num_test =,
print('spit data begin')
for i=,table.getn(children_paths) do
children_root = setting.parent_root ..'/'..children_paths[i]
print(children_root)
img_names = list_img(children_root)
ranIdx = torch.randperm(table.getn(img_names))
for j=,table.getn(img_names)do
if j<=math.floor(0.6*table.getn(img_names)) then
local idx = ranIdx[{j}]
train_paths[num_train] = children_root .. '/'..img_names[idx]
train_labels[num_train]=i
num_train = num_train+
else
local idx = ranIdx[{j}]
test_paths[num_test]=children_root .. '/' ..img_names[idx]
test_labels[num_test]=i
num_test = num_test+
end
end
end
print('begin copy')
local nTrain,nTest = table.getn(train_paths),table.getn(test_paths)
for i=1,nTrain do
local aimpath = '/home/yqcui/image/train/'..train_labels[i]..'/'..i..'.jpg'
local todo='cp '..train_paths[i]..' ' ..aimpath
print(todo)
os.execute(todo)
end
for i=,nTest do
local aimpath = '/home/yqcui/image/train/'..test_labels[i]..'/'..i..'.jpg'
local todo='cp '..test_paths[i]..' ' .. aimpath
print(todo)
os.execute(todo)
end
将数据分为数据集和训练集,比例为6:4
LUA中将未分类数据分为测试集和训练集的更多相关文章
- Matlab划分测试集和训练集
% x是原数据集,分出训练样本和测试样本 [ndata, D] = size(X); %ndata样本数,D维数 R = randperm(ndata); %1到n这些数随机打乱得到的一个随机数字序列 ...
- 【ML入门系列】(一)训练集、测试集和验证集
训练集.验证集和测试集这三个名词在机器学习领域极其常见,但很多人并不是特别清楚,尤其是后两个经常被人混用. 在有监督(supervise)的机器学习中,数据集常被分成2~3个,即:训练集(train ...
- 【Machine Learning】训练集 验证集 测试集区别
最近在Udacity上学习Machine learning课程,对于验证集.测试集和训练集的相关概念有些模糊.故整理相关资料如下. 交叉检验(Cross Validation) 在数据分析中,有些算法 ...
- 斯坦福大学公开课机器学习:advice for applying machine learning | model selection and training/validation/test sets(模型选择以及训练集、交叉验证集和测试集的概念)
怎样选用正确的特征构造学习算法或者如何选择学习算法中的正则化参数lambda?这些问题我们称之为模型选择问题. 在对于这一问题的讨论中,我们不仅将数据分为:训练集和测试集,而是将数据分为三个数据组:也 ...
- [DeeplearningAI笔记]改善深层神经网络1.1_1.3深度学习使用层面_偏差/方差/欠拟合/过拟合/训练集/验证集/测试集
觉得有用的话,欢迎一起讨论相互学习~Follow Me 1.1 训练/开发/测试集 对于一个数据集而言,可以将一个数据集分为三个部分,一部分作为训练集,一部分作为简单交叉验证集(dev)有时候也成为验 ...
- 机器学习基础:(Python)训练集测试集分割与交叉验证
在上一篇关于Python中的线性回归的文章之后,我想再写一篇关于训练测试分割和交叉验证的文章.在数据科学和数据分析领域中,这两个概念经常被用作防止或最小化过度拟合的工具.我会解释当使用统计模型时,通常 ...
- Machine Learning笔记整理 ------ (二)训练集与测试集的划分
在实际应用中,一般会选择将数据集划分为训练集(training set).验证集(validation set)和测试集(testing set).其中,训练集用于训练模型,验证集用于调参.算法选择等 ...
- 9. 获得图片路径,构造出训练集和验证集,同时构造出相同人脸和不同人脸的测试集,将结果存储为.csv格式 1.random.shuffle(数据清洗) 2.random.sample(从数据集中随机选取2个数据) 3. random.choice(从数据集中抽取一个数据) 4.pickle.dump(将数据集写成.pkl数据)
1. random.shuffle(dataset) 对数据进行清洗操作 参数说明:dataset表示输入的数据 2.random.sample(dataset, 2) 从dataset数据集中选取2 ...
- SpringBoot(18)---通过Lua脚本批量插入数据到Redis布隆过滤器
通过Lua脚本批量插入数据到布隆过滤器 有关布隆过滤器的原理之前写过一篇博客: 算法(3)---布隆过滤器原理 在实际开发过程中经常会做的一步操作,就是判断当前的key是否存在. 那这篇博客主要分为三 ...
随机推荐
- BZOJ1298[SCOI2009]骰子的学问
Description Input 第一行为两个整数n, m.第二行有n个整数,为a1,a2, -, an. Output 包含n行,每行m个1~n×m的正整数,各不相同,以空格分开.如果有多解,输出 ...
- Spring启动后扫描解析注解的过程
对应的类: ComponentScanBeanDefinitionParser.parse() ClassPathBeanDefinitionScanner.doScan() 参考 http://bl ...
- [LeetCode] Word Frequency 单词频率
Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity ...
- mac 多php版本安装
mac上自带又apache和php. 自带的php缺少一些扩展(freeType),安装起来因为mac本身有一些sudo su都不可触及的权限,所以决定不动系统本身php,再装一个新的php不同版本. ...
- asp.net使用Get请求webservice
先在Web.config中的System.Web节点下添加如下代码,使其支持Get请求: <webServices> <protocols> <add name=&quo ...
- NSRunLoop的进一步理解
iPhone应用开发中关于NSRunLoop的概述是本文要介绍的内容,NSRunLoop是一种更加高明的消息处理模式,他就高明在对消息处理过程进行了更好的抽象和封装,这样才能是的你不用处理一些很琐碎很 ...
- Servlet学习:实现分页效果的方法
分页的算法:需要定义四个变量,它们有各自的用处int pageSize:每页显示多少条记录int pageNow:希望显示第几页int pageCount:一共有多少页int rowCount:一共有 ...
- window.hostory(浏览器的历史记录)
浏览器会对同一个窗口(选项卡)中访问的网页进行记录,不管我们是通过以下哪种方式改变网页,浏览器都会把改变后的网页记录下来,以便通过浏览器的前进和后退按钮,能够快速的切换到已经访问过的网页: 1)直接 ...
- Mysql多表表关联查询 inner Join left join right join
Mysql多表表关联查询 inner Join left join right join
- linux基本命令
常用命令: w 查看登入用户(第一行为主机负载) ifconfig -a 查看所有网络 dhclient 自动获取IP地址 关机命令 init0 shutdown -h now 重启命令 init 6 ...