AttributeError: module 'tensorflow' has no attribute 'placeholder'

Seems like a tf version error in week 3 assignment.

My code:

# GRADED FUNCTION: sigmoid

def sigmoid(z):
    
    """
    Computes the sigmoid of z
    
    Arguments:
    z -- input value, scalar or vector
    
    Returns: 
    a -- (tf.float32) the sigmoid of z
    """
    # tf.keras.activations.sigmoid requires float16, float32, float64, complex64, or complex128.
    
    # (approx. 2 lines)
    # z = ...
    # a = ...
    # YOUR CODE STARTS HERE
    # Create a placeholder for x. Name it 'x'.
#     tf.disable_eager_execution()
    x = tf.placeholder(tf.float32, name="x")

    # compute sigmoid(x)
    sigmoid = tf.sigmoid(x)

    # Create a session, and run it. Please use the method 2 explained above. 
    # You should use a feed_dict to pass z's value to x. 
    with tf.Session() as sess: 
        # Run session and call the output "result"
        result = result = sess.run(sigmoid, feed_dict = {x: z})

#     tf.convert_to_tensor(result, dtype=tf.float32)
    # YOUR CODE ENDS HERE
    return result

I keep getting this error. I tried tf.disable_eager_execution() but then my result type is numpy.float
How do I fix this?

Hi, @mansi.

The notebooks use TensorFlow 2. You may find this helpful.

Regarding the exercise, take a look at the hint. You only need two lines of code:

z = ...
a = ...

Good luck with the assignment :slight_smile: