All tests passed but getting 50% because 'gen' is not defined

I just finished the programming assignment for week 4 of the first course in TensorFlow. Even though I get 100% accuracy and pass all the tests, I am failing the assignment because apparently ‘gen’ is not defined even though I define it in my notebook as asked. I have attached screenshots of my results in the notebook and the grader output I am getting. Please help me, thanks.

1 Like

can anyone help please? it has been a day and no response? lol

Please click my name and message your notebook as an attachment.

Can you please send me your notebook in pm as pdf…i shall have a look at it and report it to git if needed

The answer is very likely to be the exact same as the one in this thread, which describes the exact same error:

Does this solution work for you sir?

Hello @ra53 ,

If your problem is still not solved, you can send me your notebook in message.

With regards,
Nilosree Sengupta

@ra53 I’ve passed your notebook to @nilosreesengupta and @MayankGhogale

Hello @balaji.ambresh ,

Thank you for sending the notebook. I am looking into it.

With regards,
Nilosree Sengupta

Hello @ra53 ,

I have cleared your error.
In the part of history = , you have used x=gen.
Instead of using x=gen, write x=train_generator,

I mean, it should be like this :

history =,

With this, your present error will be cleared. Passed with 100%.

With regards,
Nilosree Sengupta

I hope this helps you sir…i am extremely sorry i couldn’t look into the error as i was caught up with my university submissions

My take on why this caused a problem is because in the OP notebook, gen was defined outside of the graded function scope. It worked in the Jupyter runtime because of the way it treats notebook-scope variables. However, in the autograder that context is lost, so the variable gen no longer is defined. If this is true, it is another example of the use of a global variable inside a graded function failing the grader. And thus the real lesson here is +1 on the directive “Don’t use global variables in graded functions.”

Did I miss something?

No u didnt @ai_curious …it is on point as always sir
And yes this is one of the explanations even i thought of…sorry i was caught up in submissions so couldn’t look much into the issue
I hope its resolved
Thanks @ai_curious @nilosreesengupta @balaji.ambresh
Also thanks @ra53 for your patience sir

Right explanation @ai_curious.

It’s alright @MayankGhogale !! Thanks for responding in your busy schedules.

Presently I have cleared the error and resolved the issue.Hope it helps @ra53 to pass the graded assignment with 100%.

With regards,
Nilosree Sengupta

I’ve been involved with Deeplearning courses and Specializations for 5 years now, and this practice of fixing learners’ code for them seems to be a fairly recent development. Have to say I am not an advocate. First of all, it is bad business practice. It sets up an expectation that doesn’t scale - there will always be more buggy notebooks than mentors. Secondly, not only does the community as a whole not learn from a fix like this, even the notebook owner may not since the root cause isn’t always revealed or explained. Finally, while I think it is bad enough in the other courses, note that the successful completion of this one results in a ‘Developer Professional Certificate’. What does it say about the holders of a certificate if they can’t use the forum search to find previous discussions containing the exact same error, draw conclusions about the condition discussed, and fix their own code, which after all is exhibiting a well known anti-pattern that no ‘professional’ developers should be practicing anyway. I think it is great if mentors can isolate errors and ensure they are not system induced, but I can’t understand the benefit of fixing code so that people can get a score from the grader they couldn’t earn on their own. Just because you can fix peoples’ code for them doesn’t mean you should do.

1 Like