티스토리 뷰

 

파이썬에서

TensorFlow 2 하다가...

a = tf.constant(10)
b = tf.constant(20)

c = a + b
d = (a+b).numpy()   #<-여기서 에러떴음

print(type(c))
print(c)
print(type(d), d)

d_numpy_to_tensor = tf.convert_to_tensor(d)

print(type(d_numpy_to_tensor))
print(d_numpy_to_tensor)

 

AttributeError                            Traceback (most recent call last)
Input In [44], in <cell line: 5>()
      2 b = tf.constant(20)
      4 c = a + b
----> 5 d = (a+b).numpy()
      7 print(type(c))
      8 print(c)

File ~\anaconda3\lib\site-packages\tensorflow\python\framework\ops.py:446, in Tensor.__getattr__(self, name)
    437 if name in {"T", "astype", "ravel", "transpose", "reshape", "clip", "size",
    438             "tolist", "data"}:
    439   # TODO(wangpeng): Export the enable_numpy_behavior knob
    440   raise AttributeError(
    441       f"{type(self).__name__} object has no attribute '{name}'. " + """
    442     If you are looking for numpy-related methods, please run the following:
    443     from tensorflow.python.ops.numpy_ops import np_config
    444     np_config.enable_numpy_behavior()
    445   """)
--> 446 self.__getattribute__(name)

AttributeError: 'Tensor' object has no attribute 'numpy'
더보기
AttributeError                            Traceback (most recent call last)
Input In [44], in <cell line: 5>()
      2 b = tf.constant(20)
      4 c = a + b
----> 5 d = (a+b).numpy()
      7 print(type(c))
      8 print(c)

File ~\anaconda3\lib\site-packages\tensorflow\python\framework\ops.py:446, in Tensor.__getattr__(self, name)
    437 if name in {"T", "astype", "ravel", "transpose", "reshape", "clip", "size",
    438             "tolist", "data"}:
    439   # TODO(wangpeng): Export the enable_numpy_behavior knob
    440   raise AttributeError(
    441       f"{type(self).__name__} object has no attribute '{name}'. " + """
    442     If you are looking for numpy-related methods, please run the following:
    443     from tensorflow.python.ops.numpy_ops import np_config
    444     np_config.enable_numpy_behavior()
    445   """)
--> 446 self.__getattribute__(name)

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

 

-> 

문서 내에서

#Tensorflow 2 설치 후 Tensorflow 2 사용
import tensorflow.compat.v1 as tf1

tf1.disable_v2_behavior() #tensorflow version 2를 사용 안 하겠다.

를 수행? 실행시켰기 때문에 이 문서 내에서는 더이상 Tensorflow2의 것들을 사용할 수 없음.

 

 

-> 새로운 문서에서

Tensorfow2를 import하고 안의 속성들을 사용하면 됨.

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함