1

I encountered this error, how do I resolve it?

NotImplementedError: Cannot convert a symbolic Tensor (lstm_2/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
# train the model
model = define_model(vocab_size, max_length)
# train the model, run epochs manually and save after each epoch
epochs = 20
steps = len(train_descriptions)
for i in range(epochs):
    # create the data generator
    generator = data_generator(train_descriptions, train_features, tokenizer, max_length)
    # fit for one epoch
    model.fit_generator(generator, epochs=1, steps_per_epoch=steps, verbose=1)
    # save model
    model.save('model_' + str(i) + '.h5')
Flavia Giammarino
  • 7,987
  • 11
  • 30
  • 40
ThE 2K KiD
  • 43
  • 1
  • 5
  • Are you using custom layers with numpy calls? if so, check if there is a tensorflow countorpart for this numpy function, usually must functions are adapted for tensorflow – Sascha Kirch Jan 14 '22 at 14:07
  • 1
    Have you read [this thread](https://stackoverflow.com/questions/66207609/notimplementederror-cannot-convert-a-symbolic-tensor-lstm-2-strided-slice0-t) ? – Mohan Radhakrishnan Jan 14 '22 at 14:11
  • @MohanRadhakrishnan Yeah now i resolved it by changing the ops.py file and Thanks – ThE 2K KiD Jan 14 '22 at 16:56

2 Answers2

0

As others have indicated elsewhere this is due to an incompatibility between specific tensorflow versions and specific numpy versions.

conda version 4.11.0

Commands to setup working environment:

conda activate base
conda env remove -y --name myenv
conda create -y --name myenv tensorflow=2.4.0
conda activate myenv
conda install -y numpy=1.19.2
conda install -y keras

System Information

System:    Kernel: 5.4.0-100-generic x86_64 bits: 64 compiler: gcc v: 9.3.0 
           Desktop: Cinnamon 5.2.7 wm: muffin dm: LightDM Distro: Linux Mint 20.3 Una 
           base: Ubuntu 20.04 focal 
Machine:   Type: Laptop System: LENOVO product: 20308 v: Lenovo Ideapad Flex 14 serial: <filter> 
           Chassis: type: 10 v: Lenovo Ideapad Flex 14 serial: <filter> 
           Mobo: LENOVO model: Strawberry 4A v: 31900059Std serial: <filter> UEFI: LENOVO 
           v: 8ACN30WW date: 12/06/2013 
CPU:       Topology: Dual Core model: Intel Core i5-4200U bits: 64 type: MT MCP arch: Haswell 
           rev: 1 L2 cache: 3072 KiB 
           flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx bogomips: 18357 
           Speed: 798 MHz min/max: 800/2600 MHz Core speeds (MHz): 1: 798 2: 798 3: 798 4: 799 
Graphics:  Device-1: Intel Haswell-ULT Integrated Graphics vendor: Lenovo driver: i915 v: kernel 
           bus ID: 00:02.0 chip ID: 8086:0a16 
           Display: x11 server: X.Org 1.20.13 driver: modesetting unloaded: fbdev,vesa 
           resolution: 1366x768~60Hz 
           OpenGL: renderer: Mesa DRI Intel HD Graphics 4400 (HSW GT2) v: 4.5 Mesa 21.2.6 
           compat-v: 3.0 direct render: Yes 
 
Tarik
  • 10,810
  • 2
  • 26
  • 40
0

In my case was because for another library I had to update numpy to version 1.21.

Numpy >= 1.20+ is not compatible with the version of tensorflow (v2.4.4). https://github.com/tensorflow/tensorflow/issues/47691.

So after uninstall numpy and install the version < 1.21 worked.

pip install numpy~=1.19.5
Cristian Zumelzu
  • 842
  • 10
  • 15