Course 4, week 1, assignment 2 - Completely Lost

I started this without knowing Python or TensorFlow or Keras and am completely lost on Course 4, week 1, assignment 2. Nothing I’ve tried for 3.1 even compiles. It does not seem there is enough information in the videos and assignment to learn the Keras syntax, and while there is plenty of outside material available, anything I’ve tried gives me incredibly cryptic errors like:

ValueError: The first argument to must always be passed.
AttributeError: ‘tuple’ object has no attribute ‘lower’

Can someone point me in the direction of some code that will at least create a layer of any kind without a compile error? I can probably figure out the rest if I get that far.

It is also less than helpful that the code gives ‘all tests pass’ if you don’t add any code at all, so you have no real way of knowing if you are correct.

Yes, the Keras syntax does take some getting used to and the material here doesn’t really give that much guidance. We’re also not supposed to post solution code here on the forums, but it’s ok to post exception traces. Here’s a thread which shows an exception trace that reveals some correct and some incorrect Sequential layer calls. The text then discusses what is wrong in the incorrect case. See if that helps get things going in the right direction …

I think I stumbled through it. I just wish that:

  1. There should be some clue or hint that you need to start with an InputLayer before your ZeroPadding2D. The exercise lays out a very descriptive overview of all the layers in your model stack, but never mentions an input layer. This is probably obvious to someone familiar with Keras, but they wouldn’t be taking this course. I only found it after lots of googling material unrelated to the course.

  2. I believe this was the first exercise (including courses 1-3) that did not have helpful unit tests. Every other exercise, if I ran my code and saw “All tests passed!”, I knew I did it right. But this exercise says “All tests passed!” for anything that compiles, including the initial code!

  3. I believe this was the first exercise where we did not have a place for print statements between # YOUR CODE STARTS HERE and # YOUR CODE ENDS HERE. I know it was easy enough to add print statements outside the code we are supposed to change, but I don’t like doing that. If you screw up something inadvertently, it is hard to get the original code back.

Overall, I found this frustrating, and was much happier with the first assignment and the assignments in courses 1 & 2.

I agree this all could be better documented. Sorry that this was so frustrating, but there is still the opportunity for learning. Here are some responses:

  1. You don’t need a separate input layer, although there is no harm in doing it that way. You can achieve the equivalent by supplying the appropriate input_shape argument to the first ZeroPad layer. If you observe that input_shape is not documented on the ZeroPad doc page, that’s because it is inherited from the parent Layers class. They tell you in the comments for the ZeroPad layer to include the input shape, although they don’t give you the variable name to use.

  2. You are misreading what the unit test does in that cell. Have a look at the comparator function by clicking “File → Open” and looking around. It is comparing every layer to the expected values as shown in that cell. If you get one function or parameter wrong, the test will throw. Try changing one of the stride or filter values and watch what happens.

  3. Generally speaking, you can add print statements whereever you want, even in the “START/END” blocks and nothing bad happens. If they give you a hint about the number of lines, that is just that: a hint. You can have more or fewer lines and it is immaterial. But the problem here is that the “START/END” block is within the “Sequential” object definition, so print statements don’t syntacticly make sense in that context. Sorry. But we get to see what happens in the test cell: it prints the definitions of all the layers in the Sequential object we defined.