Skip to content

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

@neoneye

Description

@neoneye

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions