1 Star 6 Fork 7

贾伟 / PlantVillage-Dataset

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
generate_data_for_SVM.py 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env python
import glob
import random
import uuid
import shutil
import os
target_dist = "color-80-20"
def processLine(_line):
return (_line.split("\t")[0], _line.split("\t")[-1].strip())
_train = open("lmdb/"+target_dist+"/train.txt", "r")
TRAIN = []
for _line in _train.readlines():
TRAIN.append( processLine(_line))
_test = open("lmdb/"+target_dist+"/test.txt", "r")
TEST = []
for _line in _test.readlines():
TEST.append( processLine(_line))
random.shuffle(TRAIN)
random.shuffle(TEST)
TRAIN_MAPPINGS = open("SVM/train_mapping.txt", "w")
percent_of_train = 0.2
for _entry in TRAIN[:int(percent_of_train*len(TRAIN))]:
try:
os.mkdir("SVM/train/"+_entry[-1]) #Try to create the label directory
except:
pass
print "TRAIN :: Copying....", _entry
oldName = _entry[0].replace("/home/mohanty/data/final_dataset/", "")
newName = "SVM/train/"+_entry[-1]+"/"+str(uuid.uuid4()) + ".JPG"
shutil.copy(oldName, newName)
TRAIN_MAPPINGS.write(oldName+"\t"+newName + "\n")
TRAIN_MAPPINGS.close()
TEST_MAPPINGS = open("SVM/test_mapping.txt", "w")
percent_of_test = 1
for _entry in TEST[:int(percent_of_test*len(TEST))]:
try:
os.mkdir("SVM/test/"+_entry[-1]) #Try to create the label directory
except:
pass
print "TEST :: Copying....", _entry
oldName = _entry[0].replace("/home/mohanty/data/final_dataset/", "")
newName = "SVM/test/"+_entry[-1]+"/"+str(uuid.uuid4()) + ".JPG"
shutil.copy(oldName, newName)
TEST_MAPPINGS.write(oldName+"\t"+newName + "\n")
TEST_MAPPINGS.close()
Python
1
https://gitee.com/unknown-kid/PlantVillage-Dataset.git
git@gitee.com:unknown-kid/PlantVillage-Dataset.git
unknown-kid
PlantVillage-Dataset
PlantVillage-Dataset
master

搜索帮助