Please could anyone help me why I get this error “tensorflow has no attribute” variables_initializer "
One wonders if you might possibly be running TF 1.x code in a TF 2.x environment…
Caution: This API was designed for TensorFlow v1. Continue reading for details on how to migrate from this API to a native TensorFlow v2 equivalent. See the TensorFlow v1 to TensorFlow v2 migration guide for instructions on how to migrate the rest of your code.
Thanks for the reply. I tried using the same line as described in tensorflow (
K.get_session().run(tf.compat.v1. variables_initializer) and still get the same error
If you are in fact running TF 1.x code in a TF 2.x environment and haven’t done anything to migrate it, you can expect a number of issues to pop up. If you haven’t yet reviewed the TF 1 → TF 2 migration guide, it might prove helpful.
Are you running the notebook in your own local environment, or are you using the course notebook in your browser?
I’m using it in my browser.
@brianozix: it looks like you have an old version of the notebook. My code for yolo_non_max_suppression looks nothing like that. If you are bringing a saved notebook forward from the old version of the course, that just doesn’t work. The old course was based on TF1 and in April 2021 it got seriously upgraded to TF2. As ai_curious pointed out above, those two are very different.
Your best bet is to rename your current notebook out of the way and use the procedure on the FAQ Thread to get a fresh copy. I’d advise deleting all the “dot py” files as well, so that you get fresh matching copies of everything.
Then you have to read the new notebook carefully and compare it to the old one. You’ll find all kinds of differences. You can salvage some of your work from the old version, but it has to be done very carefully. They even changed some of the API definitions of the functions you are building, which has nothing to do with the TF1 to TF2 conversion. Extreme care is required.
Or I guess the other possibility is that there is something seriously weird in the configuration of your account and you’re actually in the old version of the course. But I literally don’t think that’s possible anymore.
Was the data switched from static images to video at that time? Or the input shape changed ? Since I’m not enrolled I can’t see the current code, but I know that the darknet code from 2016 on which the original code was based only worked on static, square images. Also ‘I’m using it in my browser’ doesn’t rule out running locally - I run a Jupyter server and write and run code in a browser entirely from my laptop all the time. I also note the OP’s other question about adapting YOLO to run on real time video and think maybe we don’t have all information that would be helpful in resolving this issue.
The input dataset was not changed in the upgrade, but they did make a few “improvements” to the APIs they specify that were not strictly necessary as part of the TF1 to TF2 upgrade. It’s also a good point that “using it in a browser” is still fairly ambiguous. But it is clear that the code Brian is different than what I see in my notebook for the functions. For example, here is the function def for yolo_filter_boxes:
def yolo_filter_boxes(boxes, box_confidence, box_class_probs, threshold = .6):
Notice that the order of arguments is different from what he shows. That was one of the specific changes that happened in the old to new course transition. So I think the evidence is pretty clear that Brian is using the old notebook regardless of the environment in which it is being run.