So, this might be a dumb or obvious question but bear with me. I'm a mathematics student, and I'm in my final year and have been learning to work with neural nets for fun. I am no programmer so errors are something I encounter frequently. Usually I can sort them out, today however I received one I just can't figure out. When I attempt to execute my code I get an error saying:
"Traceback (most recent call last):
File "C:\Python Practice\gan.py", line 93, in <module>
n()
File "C:\Python Practice\gan.py", line 73, in nn
with tf.Session as sess:
AttributeError: __enter__
The code from line 72 until the end looks like:
def network_run():
with tf.Session as sess:
sess.run(tf.global_variables_initializer())
for i in range(200):
sess.run(opt_D, feed_dict={x_ten: images[np.random.choice(range(len(images)), batch_size)].reshape(batch_size, x_ten_size),
z_ten:z_noise(batch_size)})
sess.run(opt_G, feed_dict={z_ten:z_noise(batch_size)})
sess.run(opt_G, feed_dict={z_ten:z_noise(batch_size)})
gen_cost=sess.run(G_img, feed_dict={z_ten:z_noise(batch_size)})
disc_cost=sess.run(D_img, feed_dict={x_ten: images[np.random.choice(range(len(images)), batch_size)].reshape(batch_size, x_ten_size),
z_ten:z_noise(batch_size)})
image=sess.run(G(z_ten), feed_dict={z_ten:z_noise(batch_size)})
df=sess.run(tf.sigmoid(D_img_fake), feed_dict={z_ten:z_noise()})
print (i, gen_cost, disc_cost, image.max(), df[0][0])
image=sess.run(G(z_ten), feed_dict={z_ten:z_noise(batch_size)})
image1 = image[0].reshape([28, 28])
im = Image.fromarray(image1)
im.show()
network_run()
Thanks in advance to anyone who helps this blubbering fool out- Max
This looks like a simple typo. The following line in your code:
with tf.Session as sess:
...should have parentheses after Session
, like so:
with tf.Session() as sess:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With