title: ValueError using Keras and Tensorflow in R
body: <p>I am using Keras in R to reproduce a tutorial I found online. Here are my codes:</p>
  <pre><code>library(caret)
  library(dplyr)
  library(ROCR)
  
  library(devtools)
  install_github('rstudio/reticulate',force=T)
  library(reticulate)
  library(tensorflow)
  install_tensorflow(version= &quot;2.3.0&quot;)
  install_github(&quot;rstudio/keras&quot;,force=T)
  library(keras)
  keras::install_keras()
  setwd(&quot;~/Desktop/TMA_model&quot;)
  
  #------------------------------------------------------------#
  #-------------- Module 1: Data preparation ------------------#
  #------------------------------------------------------------#
  
  
  
  
  source('feature_preprocessing.R')
  
  
  
  
  # if we want to run prediction with pathological data
  allFeatures_forModel &lt;- allFeatures_forModel[complete.cases(allFeatures_forModel),]
  
  
  #------------------------------------------------------------#
  #------------ Module 2: Construct Neural Network ------------#
  #------------------------------------------------------------#
  
  # split to training and testing set
  index &lt;- createDataPartition(allFeatures_forModel$Outcome, p = 0.7, list = F)
  
  X_train &lt;- allFeatures_forModel[index, -ncol(allFeatures_forModel)]
  X_test &lt;- allFeatures_forModel[-index, -ncol(allFeatures_forModel)]
  
  
  # change the outcome to categorical data
  
  train_outcome &lt;- as.vector(as.numeric(as.character(allFeatures_forModel[index, 
  ncol(allFeatures_forModel)])))
  y_train &lt;- to_categorical(train_outcome)
  
  test_outcome &lt;- as.vector(as.numeric(as.character(allFeatures_forModel[-index, 
  ncol(allFeatures_forModel)])))
  y_test &lt;- to_categorical(test_outcome)
  
  # model construction !!
  
  model &lt;- keras_model_sequential()
  
  model %&gt;% 
    layer_dense(units = 256, activation = 'relu', input_shape = 
  ncol(X_train))%&gt;%
  layer_dropout(rate = 0.4) %&gt;%
  layer_dense(units = 128, activation = 'relu') %&gt;%
  layer_dropout(rate = 0.3) %&gt;%
  layer_dense(units = 2, activation = 'sigmoid')
  
  
  history &lt;- model %&gt;% compile(
   loss = 'binary_crossentropy',
   optimizer = 'adam',
   metrics = c('accuracy')
  )
  
  model %&gt;% fit(
    X_train, y_train, 
    epochs = 100, 
    batch_size = 5,
    validation_split = 0.3
  )
  </code></pre>
  <p>After I run the last chunk of the codes (model fitting part), I got the following error message:</p>
  <pre><code> Error in py_call_impl(callable, dots$args, dots$keywords) : 
   ValueError: in user code:
  
  /Users/mihaoyang/.virtualenvs/r-reticulate/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:806 train_function  *
      return step_function(self, iterator)
  /Users/mihaoyang/.virtualenvs/r-reticulate/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:796 step_function  **
      outputs = model.distribute_strategy.run(run_step, args=(data,))
  /Users/mihaoyang/.virtualenvs/r-reticulate/lib/python3.8/site-packages/tensorflow/python/distribute/distribute_lib.py:1211 run
      return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
  /Users/mihaoyang/.virtualenvs/r-reticulate/lib/python3.8/site-packages/tensorflow/python/distribute/distribute_lib.py:2585 call_for_each_replica
      return self._call_for_each_replica(fn, args, kwargs)
  /Users/mihaoyang/.virtualenvs/r-reticulate/lib/python3.8/site-packages/tensorflow/python/distribute/distribute_lib.py:2945 _call_for_each_r 
  </code></pre>
  <p>I understand there are some people report similar issues as I had, but seems like none of the resolution will work in my case. I appreciate any suggesiton to tackle this issue, thanks!</p>