๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

TIL/Colab

[Colab] TypeError: Cannot convert a symbolic Keras input/output to a numpy array.

๋ฌธ์ œ์ƒํ™ฉ

TypeError: Cannot convert a symbolic Keras input/output to a numpy array. This error may indicate that you're trying to pass a symbolic value to a NumPy call, which is not supported. Or, you may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model.

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

1) Numpy ๋ฒ„์ „ ๋‹ค์šด๊ทธ๋ ˆ์ด๋“œ

์ฝ”๋žฉ์—์„œ ์ฝ”๋“œ๋ฅผ ๋Œ๋ฆฌ๋˜ ์ค‘ ์œ„์™€ ๊ฐ™์€ ์—๋Ÿฌ๋ฅผ ๋งŒ๋‚ฌ๋‹ค.

numpy๋ฒ„์ „์„ ๋‚ฎ์ถ”๋Š” ํ•ด๊ฒฐ ๋ฐฉ์•ˆ์— ๋Œ€ํ•œ ๊ธ€์ด ์žˆ์–ด์„œ ์ ์šฉํ•ด๋ณด์•˜๋Š”๋ฐ ํšจ๊ณผ๊ฐ€ ์—†์—ˆ๋‹ค.

https://stackoverflow.com/questions/58479556/notimplementederror-cannot-convert-a-symbolic-tensor-2nd-target0-to-a-numpy

!pip install numpy==1.19.5

2) ํ…์„œํ”Œ๋กœ์šฐ ๋ฒ„์ „ ๋‹ค์šด ๊ทธ๋ ˆ์ด๋“œ

์‚ฌ์šฉํ•˜๋˜ ๋ชจ๋ธ Tensorflow test๋ฒ„์ „ ํ™•์ธํ•˜๊ธฐ

https://github.com/thushv89/attention_keras

TensorFlow: 1.15.0 (Tested) ๋ฒ„์ „์—์„œ ํ…Œ์ŠคํŠธ ํ–ˆ์„ ๋•Œ๋งŒ ๊ฐ€๋Šฅํ–ˆ๋‹ค๊ณ  ํ•œ๋‹ค.

๋ฒ„์ „์„ ๋‹ค์šด๊ทธ๋ ˆ์ด๋“œ ํ•˜๋Š” ๋ฐฉ๋ฒ•์€

  • ๋Ÿฐํƒ€์ž„์„ restartํ•˜๊ณ 
  • tensorflow ์ฝ”๋“œ๊ฐ€ ์‚ฌ์šฉ๋˜๊ธฐ ์ „์— ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด ์ƒˆ๋กœ์šด ๋ฒ„์ „์˜ tensorflow๋ฅผ ์„ค์น˜ํ•˜๋ฉด ๋œ๋‹ค.
!pip install tensorflow==1.15.0

๋‹ค๋ฅธ ์‚ฌ๋žŒ๋“ค ์ฝ”๋“œ๋Š” ๋Œ์•„๊ฐ€๋Š”๋ฐ, ๋‚ด ์ฝ”๋“œ๋Š” ์•ˆ ๋Œ์•„๊ฐˆ ๋•... ๋ชจ๋ธ์˜ test version ์„ ํ™•์ธํ•ด๋ณด์ž!