Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 10 months ago.
Improve this question
It looks like most predicted values are close to 0.5. How can the predicted values follow closer the original values?
normalizer = layers.Normalization()
normalizer.adapt(np.array(X_train))
model = keras.Sequential([
normalizer,
layers.Dense(8, activation='relu'),
layers.Dense(1, activation='linear'),
layers.Normalization()
])
There might be many issues here, but definitely you cannot normalize data at the output. You are literally saying "on average, I am expecting my output to be 0 and have unit variance". This makes sense iff your target is a standard, normalised Gaussian, but from the plot you can tell clearly it is not. Normalising inputs, or internal activations is fine, as there is always the final layer to apply final affine mapping. But if you do so at the end of the network, you are just making it impossible to learn most targets/signals.
Once this is solved, a network with 8 hidden neurons is extremely tiny and there is absolutely no guarantee it can learn anything, your training loss is very far from 0, you should make it much, much more expressive, and try to get your training to 0, if you can't do this - you have a bug somewhere else in the code (or the model is not expressive enough).
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed last year.
Improve this question
I am somewhat new to the concept of the metrics MAE and RMSE, I know that using these metrics instead of accuracy is reccomended since I use regression instead of classification. I am wondering how to measure the true accuracy of my model, the labeled sets are either -1 or 1 depending on the specified inputs, and my model outputs both negative and positive numbers linearly. Here are the following graphs that were returned on training:
My model doesn't appear to look overfitted in comparison to both training and testing lines, also what does it signify that RMSE is .5 and cannot go any lower? Thank you.
Mean squared error calculates the squared difference between the predicted labels and the true labels.
On the other hand, Root mean squared error calculates the squared difference between the predicted labels and the true labels just like MSE, but unlike MSE, it then takes the square root of it. Therefore, RMSE calculates the absolute distance between the predicted labels and the true labels.
For example, if your model predicts 1 but the true label is -1, then,
MSE = {1-(-1)}^2 = 4
RMSE = √MSE = √4 = 2
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
In TensorFlow we have tf.nn.softmax_cross_entropy_with_logits which only allows you to use your predicted logits and the index of gold labels (one-hot). However, sometimes we want to compute the cross entropy of two distributions, i.e., the gold standard is not one-hot. How can I achieve this purpose?
Actually tf.nn.softmax_cross_entropy_with_logits does not impose the restriction that labels must be on-hot encoded, so you can go ahead and use non-one-hot label vectors. You might be confusing this with tf.nn.sparse_softmax_cross_entropy_with_logits which does impose this restriction.
To the other part of your question– if you want to compute the cross-entropy between two normalized distributions in tensors p and q, you can use the formula yourself if you make sure use tf.math.xlogy so that you get zero for x=0 and y=0. So, letting p and q be two tensors representing normalized distributions across axis 1 you would have–
ce = - tf.reduce_sum(tf.math.xlogy(p, q), axis=1)
On the other hand, its likey that you actually have some logits that are output by a model (rather than a normalized distribution q that is computed from the logits). In this case it would be better to compute the cross-entropy by applying log-softmax of your logits
ce = - tf.reduce_sum(p * tf.nn.log_softmax(logits, axis=1), axis=1)
(thereby avoiding numerical instability of explicitly computing a softmax distribution and then immediately taking it's log). In the typical ML setting p would be your "labels" and q & logits is the output of your model. Note that this works fine for non-one-hot labels p.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have model subclassing the tensorflow.keras.models.Model class. The call method returns [output_1, ouput_2], where output_1 and output_2 have different shapes. How can I pack both outputs to be used on the same loss function? (Have y_pred on the custom loss be the list returned by the call method)
Do you necessarily need the neural net output to be 2 separate outputs?
Instead, you could combine them into one output and then separate them out later once you are using the data in the rest of your application. To combine them, use a tf.keras.layers.concatenate layer after your last layers, which will combine your 2 outputs into 1. That way, the only 1 vector needs to be passed to the loss function.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I followed a tutorial about detecting objects using deep learning here: https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html
At some point, after training up to 4082 steps, i stopped the training using CTRL+C.
Now i have bunch of files under my training directory, which looks like this:
list of files in the training directory
The question is, how do i proceed now? what to do next? the tutorial doesn't teach you how to use the training data, how to even test it if its recognizing correctly.
Thanks in advance.
The files you obtained are checkpoints. What you want to do now is to restore your model from the checkpoints. Indications from CV tricks:
with tf.Session() as sess:
model = tf.train.import_meta_graph('my_test_model-1000.meta')
model.restore(sess, tf.train.latest_checkpoint('./'))
After, you can evaluate your model on your test set:
test_accuracy = tfe.metrics.Accuracy()
for (x, y) in test_dataset:
logits = model(x)
prediction = tf.argmax(logits, axis=1, output_type=tf.int32)
test_accuracy(prediction, y)
print("Test set accuracy: {:.3%}".format(test_accuracy.result()))
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am new to tensorflow and trying to look at different examples of tensorflow to understand it better.
Now I have seen this line being used in many tensorflow examples without mentioning of any specific embedding algorithm being used for getting the words embeddings.
embeddings = tf.Variable(tf.random_uniform((vocab_size, embed_dim), -1, 1))
embed = tf.nn.embedding_lookup(embeddings, input_data)
Here are some examples:
https://github.com/Decalogue/dlnd_tv_script_generation/blob/master/dlnd_tv_script_generation.py
https://github.com/ajmaradiaga/cervantes-text-generation/blob/master/cervants_nn.py
I understand that the first line will initialize the embedding of the words by random distribution but will the embedding vectors further be trained in the model to give more accurate representation of the words (and change the initial random values to more accurate numbers) and if yes what is the actual method being used when there is no mention of any obvious embedding methods such as using word2vec and glove inside the code (or feeding the pre_tained vectors of these methods instead of random numbers in the beginning)?
Yes, those embeddings are trained further just like weights and biases otherwise representing words with some random values wouldn't make any sense. Those embeddings are updated while training like you would update a weight matrix, that is, by using optimization methods like Gradient Descent or Adam optimizer, etc.
When we use pre-trained embeddings like word2vec, they're already trained on very large datasets and are quite accurate representations of words already hence, they don't need any further training. If you are asking how those are trained, there are two main training algorithms that can be used to learn the embedding from the text; they are Continuous Bag of Words (CBOW) and Skip Grams. Explaining them completely is not possible here but I would suggest taking help from Google. This article might get you started.