Artificial Neural Network

You are currently auditing this course.
3 / 4

Artificial Neural Networks - Session 02

Slides

INSTRUCTIONS

Latest Instructions for launching Tensorboard

If you are facing challenges opening Tensorboard, please visit the below link:

https://discuss.cloudxlab.com/t/solved-cannot-start-tensorboard-server/5146


No hints are availble for this assesment

Answer is not availble for this assesment

Please login to comment

67 Comments

Hi Team,

 

I could not understood this part of code:

1. with tf.name_scope("eval"):
2.   correct = tf.nn.in_top_k(logits, y, 1)
3.   accuracy = tf.reduce_mean(tf.cast(correct, tf.float32))

Sometime, Sandeep says logits are our categories which is 0-9 and sometime he says it is calaculated field. Please explain what is happening in line number 2. I have seen the whole lecture many times where he explains this but I am not able to get it. May be some example can help me to understand it better. I am not able to visualize what is logits inside the argument.

Regards,

Birendra Singh

  Upvote    Share

Hi,

In tf.nn.in_top_k, logits are the final predictions, y is the actual class, and 1 means the k value. Feel free to check https://www.tensorflow.org/api_docs/python/tf/math/in_top_k and https://stackoverflow.com/questions/57149583/tf-nn-in-top-klogits-y-1-out-of-range-error-but-equal-actually

Thanks.

  Upvote    Share

Hi Vagdevi,

I read the link provided by you, but still i am not clear. Can you explain me the output of below sample codes. I am not getting how these output as True and False.

1) out = tf.nn.in_top_k([[0.8,0.9,0.3], [0.1,0.6,0.4], [0.6,0.9,0.65]], [1,2,3], 1)
    with tf.Session() as sess:
        sess.run(tf.initialize_all_variables())
        print (sess.run(out))
   Output : [ True False False]

2) out = tf.nn.in_top_k([[0.8,0.9,0.3], [0.1,0.6,0.4], [0.6,0.9,0.65]], [1,1,1], 1)
    with tf.Session() as sess:
        sess.run(tf.initialize_all_variables())
        print (sess.run(out))
   Output:  [ True  True  True]

3) out = tf.nn.in_top_k([[0.8,0.9,0.3], [0.1,0.6,0.4], [0.6,0.9,0.65]], [2,2,2], 2)
    with tf.Session() as sess:
        sess.run(tf.initialize_all_variables())
        print (sess.run(out))
   Output:  [False  True  True]

Regards,

Birendra Singh

  Upvote    Share

Hi,

tf.nn.in_top_k says whether the targets are in the top K predictions.

Thanks.

  Upvote    Share

Hi Team,

Like we have saver = tf.train.Saver() to save the model and reuse the existing model, do we have such facility in ML  libraray scikitlearn for different types of algorithm ? If yes, please let me know.

Regards,

Birendra Singh 

  Upvote    Share

Hi,

It is very much possible with pickle module. Feel free to go through https://scikit-learn.org/stable/modules/model_persistence.html.

Thanks.

 1  Upvote    Share

Hi Team,

By steps in DNN, do we mean number of iterations of back propagation and weights adjustment. So, in below line :

dnn_clf.fit(X_train, y_train, batch_size=50, steps=30000), we mean batch size of 50 rows will undergo weights adjustment until 30000 iterations are over ? And same operation is going to repeat until all batch elements are covered.

Regards,

Birendra Singh

  Upvote    Share

Hi,

In an epoch, each training sample gets a chance to update the weights of the classification algorithm. So an epoch is completed after all the batches update the function. Hence, here in the example, if the training set has 100 samples in total, and the batch size is 50, then one epoch is completed after 2 batches of the training data undergo forward propagaation and back propagation. There will be 30000 such epochs in this example.

Thanks.

 1  Upvote    Share

Thanks!

  Upvote    Share

1. Why don’t we consider negative values for RELU AFunc?

2.  how can we say that Relu is  non-linear activation function because gradient  is a constant (for x>0 like linear function) which does not depend upon the input value x at all. This implies that the weights and biases will be updated during the backpropagation process but the updating factor would be the same. In this scenario, the neural network will not really improve the error since the gradient is the same for every iteration. The network will not be able to train well and capture the complex patterns from the data.

 

  Upvote    Share

Hi,

For the first question, I am not sure what you mean by "negative values for ReLU function", I am assuming you meant why cannot ReLU output negative values. Here's a very good explanation of the same:

https://stats.stackexchange.com/questions/362588/how-can-a-network-with-only-relu-nodes-output-negative-values

Linear means to move ahead in a straight line. Please check the entire graph of ReLU and not a portion of the same because the entire graph constitutes the ReLU activation function and not just a part of it, you will notice that the output of ReLU is not linear, or in other words, not a straight line.

Thanks.

  Upvote    Share

Thank you very much for asking me to do activity in prvious query. I can relate your answer with that RELU is adding non-linearity. this is not as same as linear activation func.

 1  Upvote    Share

Hi,

What I have learned over years is that self-learning is the best form of learning.

Thanks.

  Upvote    Share

at slide 109, if i don't use relu activation then can i define neuron layer to design neural network?

  Upvote    Share

Hi,

Instead of me answering this for you, I would encourage you to try this on our lab and see the results. Don't forget to share your findings.

Thanks.

  Upvote    Share

 1  Upvote    Share

It works without activation function but act as linear regression means non-linearity will not get added without activation function.

even same result in case of MNIST and accuracy get reduced without Act Func.

 1  Upvote    Share

How much course I have to complete to get certificate?? Is Optional Projects need to complete to get the certificate?

 

  Upvote    Share

Hi Manish

You need to complete 2 projects in Big data , 3 projects in machine leanring, 2 in deep learning and one in python.

Also note that optional projects are not counted.

Regards

 

  Upvote    Share

Hi Malavika,

I have completed my course 72% and all mandetory projects and also applied for the certificate. Please tell me how much time it will take to get my certificate. Please let me know asap.

Thanks,

Manish Kumar

  Upvote    Share

Hi Manish

I have replied to your mail, Do check it

Regards

 

  Upvote    Share

Any updates regarding my certificate???

  Upvote    Share

Hi Manish

We have shared the certificates.

Do check your mail.

 

  Upvote    Share

Please ignore the 2 questions below as I was finally abe to execute those.

Just one query though!!

Why executing this code " !ls -l model_ckps/ " gives total as 2248 (pls refer to the screenshot)? While the lecture file shows the value as 600? Please comment. Thanks!

  Upvote    Share

Hi,

There is a possiblity that other files have been saved in the same folder.

Thanks.

  Upvote    Share

Issue executing the 2nd one. Please help with the resolution.

Thanks

 

 

  Upvote    Share

Hello,

I am facing error executing the 2 codes. Details of 1st one below and 2nd to follow in next comment.

Please help trouble shoot.

Thanks

  Upvote    Share

Hello sir,

It may found some silly question but i really wanted to ask that logistic regression algorithm functionali is quit similar to sigmoid activation function? are they similar? if not then what is difference between them? Functionality wise i am finding them very similar.

 

 1  Upvote    Share

Hi,

This is a very good question.

Logistic Regression actually uses the Sigmoid Function as a cost function. You can read more about it here:

https://www.analyticssteps.com/blogs/introduction-logistic-regression-sigmoid-function-code-explanation

https://towardsdatascience.com/introduction-to-logistic-regression-66248243c148

Thanks.

  Upvote    Share

Hello Sir,

What is the difference between making Neural Network using Tensorflow coding and using Tensorflow API like Keras? Which will be more usefull?. As I am very new to coding so thinking of having some easy way to code the neural network? Please suggest.

 1  Upvote    Share

Hi,

Good question!

It does not matter which library you use as long as you know the concept. It's like using a different programming language to solve the same task.

Thanks.

  Upvote    Share

Thank you sir....

  Upvote    Share

On what factor the no of hidden units depends?

  Upvote    Share

Hi,

There are no hard and fast rules, however, usually it should 2/3 the size of the input layer, plus the size of the output layer.

Thanks.

  Upvote    Share

Hello sir, i wanted to Know what isthe difference between n_inputs and n_neurons, i mean X is the input matrix - so is how are they related numerically with it? and on what basis is the bias b value computed?

  Upvote    Share

 this

  Upvote    Share

Hi,

n_input here is the input dataset. n_neurons is the number of neurons for that layer. In this function, b is a vector of zeros. 

Thanks.

  Upvote    Share

Thank you for responding sir. However i would like to confirm one more thing, is n_input total no. of inputs provided initially?

like 2 in this case?

  Upvote    Share

Hi,

Instead of me telling you, let me help you find it yourself. Right after the n_inputs statement, add 2 lines of code:

print(n_inputs)
print(n_neurons)

This will help you find out what these 2 variables contitutes.

Thanks.

 1  Upvote    Share

Hi, How is the output of different training batches consolidated to get final weights?

  Upvote    Share

Hi,

That is taken care by the Tensorflow library.

Thanks.

  Upvote    Share

Hi, I m running this code in tfv2 but showing this error please help me to resolve

import tensorflow as tf
# from tensorflow.python.feature_column import dense_features
config = tf.estimator.RunConfig(tf_random_seed=42) # not shown in the config

feature_cols = tf.contrib.learn.infer_real_valued_columns_from_input(X_train)
dnn_clf = tf.contrib.learn.DNNClassifier(hidden_units=[200, 200, 200], n_classes=10,
                                         feature_columns=feature_cols, config=config)
dnn_clf = tf.contrib.learn.SKCompat(dnn_clf) # if TensorFlow >= 1.1
dnn_clf.fit(X_train, y_train, batch_size=50, steps=40000)

AttributeError: module 'tensorflow' has no attribute 'contrib'
  Upvote    Share

other replacement for v2 i have found but please tell be replacement for

.contrib.learn

contrib as it is not present in v2 now

 

  Upvote    Share

please reply sir as i am unable to proceed further in the course

  Upvote    Share

Hi,

As suggested, please create a separate virtual environment for TF1 and TF2 and then proceed with this code. Check your mail for further instructions.

Thanks.

  Upvote    Share

sir i have uninstalled the version 1.14 then using v2 alone its showing these errors there are few changes in api's for version 2 as

 replacement for v2 i have found but please tell be replacement for

.contrib.learn

contrib as it is not present in v2 now

 

so please help me to find the replacement

  Upvote    Share

This comment has been removed.

Hello. The codes provided in this course, unfortunately, won't run in Tensorflow version 2.x. I use Google Colab to run my code. You can use Tensorflow 1.x in Colab You just have to run this command on the cell prior to running any underlying code :

%tensorflow_version 1.x

Ps: by default it will run the tf 2.x version so u need to run the above command otherwise it will show error.

This will solve your problem. All the best.

  Upvote    Share

Hi..

The ppt does not contains all slides explained by you. Please update.

Thanks and Regards..

  Upvote    Share

Hi,

Could you please help me by telling me which slides from which part of the view are you referring to?

Thanks.

  Upvote    Share

Hello

I was talking about the ppt of Artificial Neural Network. It contains only 77 slides in which the explained part is not there. 

Please do the needful 

Thanks n Regards...

 

  Upvote    Share

Hi,

Are you referring to the DNN slides? If yes, then you can find them in the DNN topic.

Thanks.

  Upvote    Share

Hi
there is also a problem in showing graph at end of notebook.

  Upvote    Share

Hi,

Please note that that code is deprecated, if you check the following URL does not work anymore:

https://tensorboard.appspot...

We would be removing it from our notebooks soon.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Hi
When I opened model_ckps in deep learning folder after all implementation of notebook of making neural network,I faced an issue as shown in screenshot. I am not able to download as shown in recording session. Plz help.
Thanks

  Upvote    Share

Hi,

Could you please upload the screenshot that you referred to in your comment.
Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Hi
I m sorry, i just forgot to attach. Plz find

below now:

  Upvote    Share

Hi,

Would request you to pull the latest notebooks from our repository, also, could you please check in which part of the code are you unable to create the checkpoint.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Hi
I have done git pull but still showing same error. And code is doing well, there is no issue of creating checkpoint in code.What should i do now?
Thanks

  Upvote    Share

Hi,

Please note that you would not be able to view the saved checkpoints since they are a binary file which cannot be opened in Jupyter notebook. However, the file is saved properly because of which you are able to use the same for prediction.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Hi
After making neural network, it has been told in recording that we can use this as API on server side. Can you please tell me if we want to use on mobile on computer how can we use this on server side?
Thanks

  Upvote    Share

Hi,

For mobile and IoT devices you can use TensorFlow Lite. Find more about it from the link below link:

https://www.tensorflow.org/...

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Hi
Using tf.layers.dense, if we can make neuron layers then there is no need of making neuron function?

  Upvote    Share

Hi,

Yes, the tf.layer.dense adds a single layer to your model.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

what is difference between name_scope and variable scope?
do we need to initialize and run all the variables inside name_scope and variable_scope in a session or by default they get initialized?
what is actually happening when we initialize the variables and why do we need to run them?

  Upvote    Share

Hi,

Scoping is a lightweight encapsulation mechanism for TensorFlow to share variables. The difference between the tf.name_scope() and tf.variable_scope(0 is very subtle.

- tf.variable_scope() seems to be the preferred mechanism for variable sharing.
- name_scope() is more used for name spacing operators, tf.get_variable() ignores name_scopes() unless the with operator is used.
Hope that answers your queries.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

I am havinf python 2.7 in console.
I would like to switch to 3.6
but when I am trying activate python36, it is displaying command not found.
I followed steps mentioned in video, but I couldn't make it.

Please help me to activate py36

  Upvote    Share