tensorflow - 我面临一个空的training_Data
问题描述
所以我尝试了这个教程(11:58 分钟),试图在我的 CNN 上实现,它由数据集上的 10 个物种组成。
我加载数据没有错误
DATADIR = "dataset"
CATEGORIES = ["Dendrobium_crumenatum","Grammatophyllum_speciosum", "Coelogyne_swaniana",
"Bulbophyllum_purpurascens", "Agrostophyllum_stipulatum",
"Spathoglottis_plicata", "Phalaenopsis_amabilis", "Nabaluia_angustifolia",
"Habenaria_rhodocheila_hance"]
here the example of the output
[![enter image description here][2]][2]
那么下一节是
training_data = []
def create_training_data():
for category in CATEGORIES:
path = os.path.join(DATADIR,category)
class_num = CATEGORIES.index(category)
for img in os.listdir(path):
try:
img_array = cv2.imread(os.path.join(path,img),cv2.IMREAD_GRAYSCALE)
new_array = cv2.resize(img_array, (IMG_SIZE,IMG_SIZE))
training_data.append([new,array, class_num])
except Exception as e:
pass
create_training_data()
但是当我打印prin(len(training_data))
我把这个作为输出
0
当我尝试
import random
random.shuffle(training_data)
for sample in training_data[:10]:
print (sample[1])
它没有显示输出。这是否意味着,我的训练数据是空的?还是因为正在使用的类别索引?因为我使用的是 10 课,而在教程中使用的是 2 课。
解决方案
使您的 training_data 全球化
training_data =[]
def create_training_data():
global training_data
for category in CATEGORIES:
path = os.path.join(DATADIR,category)
class_num = CATEGORIES.index(category)
for img in os.listdir(path):
try:
img_array = cv2.imread(os.path.join(path,img),cv2.IMREAD_GRAYSCALE)
new_array = cv2.resize(img_array,(IMG_SIZE, IMG_SIZE))
training_data.append([new_array,class_num])
except Exception as e:
pass
create_training_data()
推荐阅读
- string - 错误:1003遍后无法找到所有标签的有效值;为1001停滞不前,放弃
- matlab - 声明辛普森规则函数时出错,未使用变量?
- linux - 如何解压 shell 脚本中的 tgz 文件?
- spring - 为 Spring webclient 默认指标添加标签
- ckeditor5 - CKEditor 最大内容限制
- android - BottomNavigationView 正在为隐藏的系统导航栏添加空间?
- xcode - 如何修复flutter xcode ios EXC_CRASH(SIGABRT)异常问题
- mysql - mysql 5.7 和 Java 17 和 jconnect 8 的 keycloak 服务器 15.0.2 超时错误
- c++ - 如何实现可以限制内存大小的“对象缓冲区”?
- flutter - 如何在颤动的ExpansionPanels之间添加空格?