简体   繁体   English

如何修复张量流中的“ValueError: Empty Training Data”错误

[英]How to fix 'ValueError: Empty Training Data' error in tensorflow

I am new to tensorflow and keras.我是 tensorflow 和 keras 的新手。 I am trying to train a model to identify different images for rock paper and scissors.我正在尝试训练一个模型来识别石头纸和剪刀的不同图像。 I am using an online tutorial for that and they have provided me with a google collab worksheet.我正在为此使用在线教程,他们为我提供了 google collab 工作表。 When I train the model on google collab everything works fine but if I try training the model on my machine, it gives me this error: ValueValueError: Empty training data当我在 google collab 上训练模型时一切正常,但是如果我尝试在我的机器上训练模型,它会给我这个错误: ValueValueError: Empty training data
I have tried changing the batch size and also tried tried changing the amount of images in the dataset but it doesnt help(And it shouldn't).我试过改变批量大小,也试过改变数据集中的图像数量,但它没有帮助(它不应该)。

Here is my code:这是我的代码:

###### ROCK PAPER SISSORS #######

import os
import numpy as np
import cv2
import tensorflow as tf
import keras_preprocessing
from keras_preprocessing import image
from keras_preprocessing.image import ImageDataGenerator
import matplotlib.pyplot as plt
# import matplotlib.image as mpimg


# Provide the path to the directory of the classes
rock_dir = os.path.join('/media/visheshchanana/New Volume/Projects/datasets/RPS/rps/rock')
paper_dir = '/media/visheshchanana/New Volume/Projects/datasets/RPS/rps/paper'
scissors_dir = '/media/visheshchanana/New Volume/Projects/datasets/RPS/rps/scissors'


rock_files = os.listdir(rock_dir)
# print(rock_files[:10])
#  ​
paper_files = os.listdir(paper_dir)
# print(paper_files[:10])
# ​
scissors_files = os.listdir(scissors_dir)
# # print(scissors_files[:10])



# Use the augmentation tool to change the augmentation of the images so that we can have a better classifier
TRAINING_DIR = "/media/visheshchanana/New Volume/Projects/datasets/RPS/rps"
training_datagen = ImageDataGenerator(
      rescale = 1./255,
      rotation_range=40,
      width_shift_range=0.2,
      height_shift_range=0.2,
      shear_range=0.2,
      zoom_range=0.2,
      horizontal_flip=True,
      fill_mode='nearest')

# Provide the path to the validation dataset
VALIDATION_DIR = "/media/visheshchanana/New Volume/Projects/datasets/RPS/RPS_validation"
validation_datagen = ImageDataGenerator(rescale = 1./255)

train_generator = training_datagen.flow_from_directory(
    TRAINING_DIR,
    target_size=(150,150),
    class_mode='categorical'
)

validation_generator = validation_datagen.flow_from_directory(
    VALIDATION_DIR,
    target_size=(150,150),
    class_mode='categorical'
)

model = tf.keras.models.Sequential([
    # Note the input shape is the desired size of the image 150x150 with 3 bytes color
    # This is the first convolution
    tf.keras.layers.Conv2D(64, (3,3), activation='relu', input_shape=(150, 150, 3)),
    tf.keras.layers.MaxPooling2D(2, 2),
    # The second convolution
    tf.keras.layers.Conv2D(64, (3,3), activation='relu'),
    tf.keras.layers.MaxPooling2D(2,2),
    # The third convolution
    tf.keras.layers.Conv2D(128, (3,3), activation='relu'),
    tf.keras.layers.MaxPooling2D(2,2),
    # The fourth convolution
    tf.keras.layers.Conv2D(128, (3,3), activation='relu'),
    tf.keras.layers.MaxPooling2D(2,2),
    # Flatten the results to feed into a DNN
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dropout(0.5),
    # 512 neuron hidden layer
    tf.keras.layers.Dense(512, activation='relu'),
    tf.keras.layers.Dense(3, activation='softmax')
])


model.summary()
model.compile(loss = 'categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])

history = model.fit_generator(train_generator, epochs=5, validation_data = validation_generator, verbose = 1)


The dataset is the same as used in the google collab.该数据集与 google collab 中使用的相同。 I can't figure out the reason behind this error.我无法弄清楚这个错误背后的原因。

此错误可能还有其他原因,但我意识到我的批次大小大于我的样本大小

I had the same problem.我有同样的问题。 My model trains and gives this error (ValueValueError: Empty training data) at the end of the first epoch.我的模型在第一个纪元结束时进行训练并给出此错误 (ValueValueError: Empty training data)。 I figured out that it was because there was no data in the validation path.我发现这是因为验证路径中没有数据。

检查steps_per_epoch是否未设置为 0(例如,由于整数除法)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TensorFlow训练数据错误。 ValueError - TensorFlow training data Error. ValueError 数据增强 TensorFlow 训练数据时如何修复错误? - How to fix the error when data augmenting TensorFlow training data? 张量流的错误将如何解决? - How the error of tensorflow will be fix? 在训练情感分析模型时如何修复 ValueError? - How can I fix a ValueError when training a model for sentiment analysis? 如何修复'ValueError:提供的元素过多。 张量流中最多是否需要错误? - How to fix 'ValueError: Too many elements provided. Needed at most' error in tensorflow? TensorFlow 在训练或验证时给出错误“InvalidArgumentError: Input is empty” - TensorFlow giving error “InvalidArgumentError: Input is empty” when training or validating 如何将 TensorFlow 训练数据导出到 CSV - How to export TensorFlow training data to CSV 如何将我的训练数据上传到谷歌以进行 Tensorflow 云训练 - How to upload my training data into google for Tensorflow cloud training 张量流训练的第一个纪元结束时出现ValueError - ValueError in the first epoch ending of tensorflow training 在TensorFlow中构建模型时如何解决ValueError? - How can I fix the ValueError when building the model in TensorFlow?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM