Getting NotImplementedError: Cannot convert a symbolic Tensor in my Recurrent Nueral Network

Viewed 21

I suspect the the problem maybe in the first layer of my RNN. Examples I have seen use an input_shape parameter but when I attempt it I still get the same error. The only example I had to go off of used an encoder for words, which is differen than what I am doing. Currently when I attempt to train my model with .fit() I get the below error.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import tensorflow as tf
from sklearn.preprocessing import MinMaxScaler

dataset_train = pd.read_csv('Google_Stock_Price_Train.csv')

training_set = dataset_train.iloc[:, 1:2].values 

sc = MinMaxScaler(feature_range = (0,1))

training_set_scaled = sc.fit_transform(training_set)

x_train = []
y_train = []

for i in range(60, 1258): #we have 1258 dates in our excel file
    x_train.append(training_set_scaled[i-60:i, 0])
    y_train.append(training_set_scaled[i, 0])

x_train, y_train = np.array(x_train),np.array(y_train)

x_train = np.reshape(x_train, (x_train.shape[0],x_train.shape[1],1))

model = tf.keras.Sequential()

model.add(tf.keras.layers.LSTM(units=128,activation='tanh', return_sequences=True))

model.add(tf.keras.layers.Dropout(0.2))

model.add(tf.keras.layers.LSTM(units=128, activation='tanh',return_sequences=True))
model.add(tf.keras.layers.Dropout(0.2))

model.add(tf.keras.layers.LSTM(units=128, activation='tanh',return_sequences=True))
model.add(tf.keras.layers.Dropout(0.2))

model.add(tf.keras.layers.LSTM(units=128, activation='tanh'))
model.add(tf.keras.layers.Dropout(0.2))

model.add(tf.keras.layers.Dense(units=1))

model.compile(optimizer = 'adam', loss = 'mean_squared_error')

model.fit(x_train, y_train, epochs=100, batch_size=32)

I get

NotImplementedError: Cannot convert a symbolic Tensor (sequential/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
0 Answers
Related