Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow 培训和测试之间的损失可以承受多少_Tensorflow_Machine Learning_Keras_Deep Learning_Mlp - Fatal编程技术网

Tensorflow 培训和测试之间的损失可以承受多少

Tensorflow 培训和测试之间的损失可以承受多少,tensorflow,machine-learning,keras,deep-learning,mlp,Tensorflow,Machine Learning,Keras,Deep Learning,Mlp,我正在训练一个在3个班级之间进行分类的模型。我每堂课只有120张图片,总共有3堂课。我已经训练了模型,但训练和测试精度之间的差异很大。它指示模型是否处于过度拟合状态或其他状态 列车和测试数据精度之间的差异各不相同。所以现在我得到了: 列车数据的模型评估[0.29664946870370346,0.91636366] 试验数据的模型评估[0.42788882246788881,0.8088235] 损失也很高。我应该考虑哪些事情来减少损失,减少列车和测试数据之间的差异 最后一件事是,我制作了自

我正在训练一个在3个班级之间进行分类的模型。我每堂课只有120张图片,总共有3堂课。我已经训练了模型,但训练和测试精度之间的差异很大。它指示模型是否处于过度拟合状态或其他状态

列车和测试数据精度之间的差异各不相同。所以现在我得到了:

  • 列车数据的模型评估[0.29664946870370346,0.91636366]
  • 试验数据的模型评估[0.42788882246788881,0.8088235]
损失也很高。我应该考虑哪些事情来减少损失,减少列车和测试数据之间的差异 最后一件事是,我制作了自己的数据集,这对于多层感知器来说足够了吗

我将120张图片分成训练和测试两部分。100用于列车,20用于试验。够了吗

import time
import numpy as np
import tensorflow as tf
from tensorflow.keras.callbacks import TensorBoard
from sklearn.model_selection import cross_val_score
from keras.wrappers.scikit_learn import KerasClassifier
data = np.load('E:\Python Telusko\OpenCv\desc_feat.npy', allow_pickle=True)
from sklearn.model_selection import train_test_split

NAME="ITA MLP-{}".format(int(time.time()))
tensorboard=TensorBoard(log_dir="E:\\ITA MLP\\logs\\{}".format(NAME))

training_data = np.asarray([i[0] for i in data])  
train_labels = data[:, -1]  
print("Shape of training data", training_data.shape)
print("Labels of training data", train_labels.shape)

data = training_data.astype('float32')
data = data / 255
from tensorflow.keras import utils as np_utils
from sklearn.model_selection import KFold

one_hot_train_labels = np_utils.to_categorical(train_labels)

def create_model():
    model = tf.keras.models.Sequential()
    model.add(tf.keras.layers.Dense(64, input_shape=(128,) , activation = 'relu'))
    model.add(tf.keras.layers.Dense(3, activation = 'softmax')) 
    model.compile(loss = 'categorical_crossentropy' , optimizer = 'adam' , metrics = ['accuracy'] ) 
    return model

n_split=5
 
for train_index,test_index in KFold(n_split).split(data):
    x_train,x_test=data[train_index],data[test_index]
    y_train,y_test=one_hot_train_labels[train_index],one_hot_train_labels[test_index]
    model=create_model()
    model.fit(x_train, y_train,epochs=30,batch_size=32,callbacks=[tensorboard])
    print('Model evaluation on train data ',model.evaluate(x_train,y_train))
    print('Model evaluation on test data',model.evaluate(x_test,y_test))


model.save('SuperClassPredictions1.model')

我建议您扩充数据集。使用100幅图像训练神经网络会导致过度拟合问题。神经网络总是需要大量的数据

  • 您需要监控验证损失和培训损失,以避免过度装配,并且可以使用

  • 二,。对于理想损失问题,没有具体的衡量标准。根据培训和验证损失调整模型

    这里有多个问题,似乎都是关于ML/统计,而不是编程,这意味着这可能与主题无关。请参阅.Nivesh,正如我告诉您的,我没有找到这种类型的数据集。我自己做的,我在谷歌上找到了100张图片,所以,我知道图片总数太少了,但我现在该怎么办?你可以把100张图片数据增加到更多的数字中。这就像你通过裁剪、添加变换、改变强度、噪声等创建重复的图像一样,。参考这个:我使用64个隐藏单位和一个隐藏层。训练损失远低于验证损失。我现在该怎么办。我已经调整了许多超参数,但损失的差异始终保持在conastantNivesh状态。如果过度拟合,我可以使用Drop-out删除它,而不是增加数据集。我建议增加数据集,因为您要在100张图像上进行训练。我们只在海量数据上使用学习算法。您可以使用90%的辍学率,并在测试中获得99.9%的准确率。但是,这并不意味着你的模型没有过度装配。