lazyprogrammer / machine_learning_examples

A collection of machine learning examples and tutorials.

Home Page:https://lazyprogrammer.me

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ann_class2/tensorflow1.py - migrate from tensorflow version 1 to version 2

neoneye opened this issue · comments

I'm following the how to install guide of the data-science-linear-regression-in-python course.

The code for verifying that tensorflow is working correctly, didn't work for me, so I investigated how to fix it. Here is the error I was experiencing.

PROMPT> python3 tensorflow1.py 
Traceback (most recent call last):
  File "tensorflow1.py", line 20, in <module>
    A = tf.placeholder(tf.float32, shape=(5, 5), name='A')
AttributeError: module 'tensorflow' has no attribute 'placeholder'

On TF's website there is a migration guide.

Change from

import tensorflow as tf

Change to

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

This solved it for me.

Please use the course Q&A for course-related questions