title: having trouble training my Rnn model on tensorflow and keras
body: <p>this is the code:</p>
  
  <pre><code>import pandas as pd 
  from sklearn import preprocessing  
  from collections import deque
  import numpy as np
  import random
  import time
  import tensorflow as tf
  from tensorflow.keras.models import Sequential
  from tensorflow.keras.layers import Dense, Dropout, LSTM, BatchNormalization
  from tensorflow.keras.callbacks import TensorBoard, ModelCheckpoint 
  
  
  # SETTING THE EVIRONMENT FOR  
  SEQ_LEN = 60
  FUTURE_PERIOD_PREDICT = 3 
  RATIO_TO_PREDICT = "LTC-USD"
  EPOCHS = 20
  BATCH_SIZE = 64
  
  NAME = f"{SEQ_LEN}-SEQ-{FUTURE_PERIOD_PREDICT}-PRED-{int(time.time())}"
  
  
  
  
  
  
  
  def classify(current, future):
      if float(future) &gt; float(current): 
          return 1
      else:
          return 0
  
  def preprocess_df(df):
      df = df.drop('future', 1)
  
      for col in df.columns:
          if col != "target":
              df[col] = df[col].pct_change()
              df.dropna(inplace=True)
              df[col] = preprocessing.scale(df[col].values)
  
      df.dropna(inplace=True)
  
      sequential_data = []
      prev_days = deque(maxlen=SEQ_LEN)
      for i in df.values:
          prev_days.append([n for n in i[:-1]])
          if len(prev_days) == SEQ_LEN:
              sequential_data.append([np.array(prev_days), i[-1]])
  
  
      random.shuffle(sequential_data)
  
      buys = []
      sells = []
  
      for seq, target in sequential_data:
          if target == 0:
              sells.append([seq, target])
          elif target == 1:
              buys.append([seq, target])
  
  
      random.shuffle(buys)
      random.shuffle(sells)
  
      lower = min(len(buys), len(sells))
  
      buys = buys[:lower]
      sells = sells[:lower]
  
      sequential_data = buys+sells
      random.shuffle(sequential_data)
  
      X = []
      y = []
  
      for seq, target in sequential_data:
          X.append(seq)
          y.append(target)
  
      return np.array(X), y
  
  
  main_df = pd.DataFrame()
  ratios = ["BTC-USD", "LTC-USD", "ETH-USD", "BCH-USD"]
  for ratio in ratios:
      #print(ratio)
      dataset = f"crypto_data/{ratio}.csv"
  
      df = pd.read_csv(dataset, names=["time", "low", "high", "open", "close", "volume"])
      #print(df.head())
      df.rename(columns={"close": f"{ratio}_close", "volume":f"{ratio}_volume"}, inplace=True)
  
      df.set_index("time", inplace=True)
      df = df[[f"{ratio}_close", f"{ratio}_volume" ]]
      #print(df.head())
  
      if len(main_df) == 0:
          main_df = df
      else:
          main_df = main_df.join(df)
  
      #print(main_df.head)
  
  
  # be cuz it has trancated our columns i invert using(c) it to column view
  #just for viewing process
  #for c in main_df.columns:
   #   print(c)
  
  main_df['future'] = main_df[f"{RATIO_TO_PREDICT}_close"].shift(-FUTURE_PERIOD_PREDICT)
  
  main_df['target'] = list(map(classify, main_df[f"{RATIO_TO_PREDICT}_close"], main_df["future"]))
  
  times = sorted(main_df.index.values)
  last_5pct = times[-int(0.05*len(times))]
  
  validation_main_df = main_df[(main_df.index &gt;= last_5pct)]
  main_df = main_df[(main_df.index &lt; last_5pct)]
  
  
  train_x, train_y = preprocess_df(main_df)
  validation_x, validation_y = preprocess_df(validation_main_df)
  
  print(f"train data: {len(train_x)} validation: {len(validation_x)}")
  print(f"Dont buys: {train_y.count(0)}, buys: {train_y.count(1)}")
  print(f"VALIDATION Dont buys: {validation_y.count(0)}, buys: {validation_y.count(1)}")
  
  model = Sequential()
  model.add(LSTM(128, input_shape=(train_x.shape[1:]), activation="relu", return_sequences=True))
  model.add(Dropout(0.2))
  model.add(BatchNormalization()) 
  
  
  model.add(LSTM(128,  input_shape=(train_x.shape[1:]), activation="relu", return_sequences=True))
  model.add(Dropout(0.2))
  model.add(BatchNormalization()) 
  
  
  model.add(LSTM(128,  input_shape=(train_x.shape[1:]), activation="relu", return_sequences=True))
  model.add(Dropout(0.2))
  model.add(BatchNormalization()) 
  
  
  model.add(Dense(32, activation="relu"))
  model.add(Dropout(0.2))  
  
  
  model.add(Dense(2, activation="softmax"))
  
  opt = tf.keras.optimizers.Adam(lr=0.001, decay=1e-6)
  
  model.compile(loss='sparse_categorical_crossentropy', 
                optimizer=opt,
                metrics=['accuracy'])
  
  tensorboard = TensorBoard(log_dir=f'logs\{NAME}')
  
  filepath = "RNN_Final-{epoch:02d}"
  checkpoint = ModelCheckpoint("models\{}.model".format(filepath), verbose=1, save_best_only=True, mode='max')
  
  train_y= np.asarray(train_y) 
  validation_y= np.asarray(validation_y)
  
  history = model.fit(
      train_x, train_y,
      batch_size=BATCH_SIZE,
      epochs=EPOCHS,
  
      validation_data=(validation_x, validation_y),
  
      callbacks=[tensorboard, checkpoint])
  
  this is the error:
  </code></pre>
  
  <p>InvalidArgumentError:  assertion failed: [] [Condition x == y did not hold element-wise:] [x (loss/dense_1_loss/SparseSoftmaxCrossEntropyWithLogits/Shape_1:0) = ] [64 1] [y (loss/dense_1_loss/SparseSoftmaxCrossEntropyWithLogits/strided_slice:0) = ] [64 60]
       [[node loss/dense_1_loss/SparseSoftmaxCrossEntropyWithLogits/assert_equal/Assert/Assert 
  Function call stack:
  distributed_function</p>