AttributeError: 'Tensor' object has no attribute 'numpy'

2019. 10. 3. 09:47/에러

import numpy as np
import tensorflow as tf

t = tf.constant([1, 2, 3])
t.array()
AttributeError: 'Tensor' object has no attribute 'numpy'

 

아주 간단한 코드였는데 안돼.. 오잉?

array함수가 eager execution이 되어야 하는건지

프로그램 시작하고 바로 tf.enable_eager_execution()을 입력하니 된다.

 

import numpy as np
import tensorflow as tf

tf.enable_eager_execution()
t = tf.constant([1, 2, 3])
t.array()

 

참고 : https://stackoverflow.com/questions/52357542/attributeerror-tensor-object-has-no-attribute-numpy

 

AttributeError: 'Tensor' object has no attribute 'numpy'

How can I fix this error I downloaded this code from GitHub. predicted_id = tf.multinomial(tf.exp(predictions), num_samples=1)[0][0].numpy() throws the error AttributeError: 'Tensor' object has...

stackoverflow.com

혹은 tf.Session() 사용

 

 

그런데 eager execution을 실행하고 나니

Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

라는 문구가 뜨기 시작했다. 무시해도 좋다고 하니 일단 그냥 써야겠다.

 

참고 : https://blog.naver.com/PostView.nhn?blogId=complusblog&logNo=221237740617&redirect=Dlog&widgetTypeCall=true&directAccess=false