I'm unable to resolve this problem

You filed this under DLS Course 5, but it looks to me like the YOLO assignment from DLS Course 4, Week 3. It also looks like you must have copied an old notebook from before April 2021, which uses TensorFlow 1.0 instead of 2.0 with “Eager” mode. That will not work. If you are trying to copy a solution from GitHub, also be aware that is a violation of the Honor Code. If it’s your own work saved from a long time ago, then please be aware that you can’t just port that old code forward. You’ll have to study the differences and rewrite things for TF 2 in the way that the new version of the notebook has you do it. Also note that they changed more things than strictly required by the TF1 → TF2 upgrade. They also redefined some of the specific APIs, so you really need to carefully examine everything. You can’t just blindly “copy/paste” things and expect it to work.

If you need to get a fresh copy of the notebook, there is a topic about that on the DLS FAQ Thread.