简体   繁体   English

Keras + TensorFlow Model

[英]Keras + TensorFlow Model

I'm currently creating a model and while creating it I came with some questions.我目前正在创建一个 model 并且在创建它时我提出了一些问题。 Does training the same model with the same data multiple times leads to better precision of those objects, since your training it every time?使用相同的数据多次训练相同的 model 是否会导致这些对象的精度更高,因为您每次都训练它? And what could be the issue when sometimes the object gets 90% precision and when I re-run it gets lower precision or even not predicting the right object?当有时 object 获得 90% 的精度并且当我重新运行它时精度降低甚至无法预测正确的 object 时,可能会出现什么问题? Is it because of Tensorflow running on the GPU?是因为在Tensorflow上运行的 Tensorflow 吗?

I will guess that you are doing image recognition and that you want to identify images (objects) using a neuronal network made with Keras.我猜你正在做图像识别,并且你想使用用 Keras 制作的神经网络来识别图像(对象)。 You should train it once, but during training you will do several epochs, meaning the algorithm adapts the weights in several rounds (epochs).你应该训练一次,但在训练期间你会做几个 epoch,这意味着算法会在几轮(epochs)中调整权重。 For each round it goes over all training images.对于每一轮,它都会遍历所有训练图像。 Once trained, you can use the model to identify images/objects.训练后,您可以使用 model 来识别图像/对象。

You can evaluate the accuracy of your trained model over the same training set, but it is better to use a different set (see train_test_split from sklearn for instance).您可以在相同的训练集上评估经过训练的 model 的准确性,但最好使用不同的集(例如,参见sklearn中的 train_test_split)。

Training is a stochastic process, meaning that every time you train your network it will be different in the end.训练是一个随机过程,这意味着每次训练网络时,最终都会有所不同。 Hence, you will get different accurcies.因此,您将获得不同的精度。 The stochasticity comes from different initial weights or from using stochastic gradient descent methods for instance.随机性来自不同的初始权重或来自使用例如随机梯度下降方法。

The question does not appear to have anything to do with Keras or TensorFlow but basic understandting of how neuronal networks work.这个问题似乎与 Keras 或 TensorFlow 无关,而是对神经网络如何工作的基本了解。 There is no connection to running Tensorflow on the GPU.在 GPU 上运行 Tensorflow 没有任何联系。 You will also not get better precision by training with the same objects.通过使用相同的对象进行训练,您也不会获得更好的精度。 If you train your model on a dataset for a very long time (many epochs), you might get into overfitting.如果你在一个数据集上训练你的 model 很长时间(很多 epochs),你可能会陷入过度拟合。 Then, the accuracy of your model on this training dataset will be very high, but the model will have low accuracy on other datasets.那么,你的 model 在这个训练数据集上的准确率会非常高,但是 model 在其他数据集上的准确率会很低。

A common technique is split your date in train and validation datasets, then repeatedly train your model using EarlyStopping.一种常见的技术是将您的日期拆分到训练和验证数据集中,然后使用 EarlyStopping 重复训练您的 model。 This will train on the training dataset, then calculate the loss against the validation dataset, and then keep training until no further improvement is seen.这将在训练数据集上进行训练,然后根据验证数据集计算损失,然后继续训练直到看不到进一步的改进。 You can set a patience parameter to wait for X epochs without an improvement to stop training (and optionally save the best model)您可以设置一个耐心参数以等待 X 个时期没有改进以停止训练(并可选择保存最佳模型)

Another trick is image augmentation with ImageDataGenerator which will generate synthetic data for you (rotations, shifts, mirror images, brightness adjusts, noise etc).另一个技巧是使用 ImageDataGenerator 进行图像增强,它将为您生成合成数据(旋转、移位、镜像、亮度调整、噪声等)。 This can effectively increase the amount of data you have to train with, thus reducing overfitting.这可以有效地增加你必须训练的数据量,从而减少过度拟合。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM