포스트

Tensorflow-gpu 2.4.1 vs Numpy 1.20.1 NotImplementedError 에러 발생

Tensorflow-gpu 2.4.1 vs Numpy 1.20.1

tf 2.4.1 version 과 numpy 1.20.1 버전을 사용할 때 lstm 모듈에서 에러가 발생했습니다. 레딧에서 비슷한 에러 이슈를 발견했는데 버전과 호환성 문제인 것 같아보입니다.

numpy를 다운그레이드를 해야해서 아무 버전을 설치하던 중 다음과 같은 에러로 requirment 버전을 얼떨결에 확인했네요.

1
2
ERROR: tensorflow-gpu 2.4.1 has requirement numpy~=1.19.2, but you'll have numpy 1.16.5 which is incompatible.
ERROR: tensorflow-gpu 2.4.1 has requirement six~=1.15.0, but you'll have six 1.12.0 which is incompatible
1
2
sudo -E pip install -U numpy==1.19.2
sudo -E pip install -U six==1.15.0

numpy만 1.19.2로 다운그레이드 할 경우 six가 자동으로 1.12 version 으로 깔리니 six도 같이 설치해 주세요.

NotImplementedError

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
NotImplementedError: in user code:

    <ipython-input-49-aff03841d54a>:19 train_step  *
        pred_stocks, pred_returns = model(features, True)
    <ipython-input-46-a36da6d26c41>:37 call  *
        self.lstm1 = self.lstm_1(feed_inputs)
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/keras/layers/recurrent.py:660 __call__  **
        return super(RNN, self).__call__(inputs, **kwargs)
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py:1012 __call__
        outputs = call_fn(inputs, *args, **kwargs)
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/keras/layers/recurrent_v2.py:1157 call
        inputs, initial_state, _ = self._process_inputs(inputs, initial_state, None)
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/keras/layers/recurrent.py:859 _process_inputs
        initial_state = self.get_initial_state(inputs)
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/keras/layers/recurrent.py:643 get_initial_state
        inputs=None, batch_size=batch_size, dtype=dtype)
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/keras/layers/recurrent.py:2507 get_initial_state
        self, inputs, batch_size, dtype))
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/keras/layers/recurrent.py:2987 _generate_zero_filled_state_for_cell
        return _generate_zero_filled_state(batch_size, cell.state_size, dtype)
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/keras/layers/recurrent.py:3003 _generate_zero_filled_state
        return nest.map_structure(create_zeros, state_size)
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/util/nest.py:659 map_structure
        structure[0], [func(*x) for x in entries],
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/util/nest.py:659 <listcomp>
        structure[0], [func(*x) for x in entries],
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/keras/layers/recurrent.py:3000 create_zeros
        return array_ops.zeros(init_state_size, dtype=dtype)
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py:201 wrapper
        return target(*args, **kwargs)
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/ops/array_ops.py:2819 wrapped
        tensor = fun(*args, **kwargs)
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/ops/array_ops.py:2868 zeros
        output = _constant_if_small(zero, shape, dtype, name)
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/ops/array_ops.py:2804 _constant_if_small
        if np.prod(shape) < 1000:
    <__array_function__ internals>:6 prod
        
    /opt/tljh/user/lib/python3.7/site-packages/numpy/core/fromnumeric.py:3031 prod
        keepdims=keepdims, initial=initial, where=where)
    /opt/tljh/user/lib/python3.7/site-packages/numpy/core/fromnumeric.py:87 _wrapreduction
        return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
    /opt/tljh/user/lib/python3.7/site-packages/tensorflow/python/framework/ops.py:855 __array__
        " a NumPy call, which is not supported".format(self.name))

    NotImplementedError: Cannot convert a symbolic Tensor (model/lstm/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported

참조

  1. https://www.reddit.com/r/tensorflow/comments/lgcgby/numpyrelated_error_when_building_model/
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.