title: Siamese Network using Rstudio Keras
body: <p>I'm trying to implement a siamese network using Rstudio Keras package. The network I'm trying to implement is the same network that you can see in <a href="https://sorenbouma.github.io/blog/oneshot/" rel="nofollow noreferrer">this post</a>.</p>
  
  <p>So, basically, I'm porting the code to R and using Rstudio Keras implementation. So far my code looks like this:</p>
  
  <pre><code>    library(keras)
  
      inputShape &lt;- c(105, 105, 1)
      leftInput &lt;- layer_input(inputShape)
      rightInput &lt;- layer_input(inputShape)
  
      model&lt;- keras_model_sequential()
  
      model %&gt;%
        layer_conv_2d(filter=64,
                      kernel_size=c(10,10),
                      activation = "relu",
                      input_shape=inputShape,
                      kernel_initializer = initializer_random_normal(0, 1e-2),
                      kernel_regularizer = regularizer_l2(2e-4)) %&gt;%
        layer_max_pooling_2d() %&gt;%
  
        layer_conv_2d(filter=128,
                      kernel_size=c(7,7),
                      activation = "relu",
                      kernel_initializer = initializer_random_normal(0, 1e-2),
                      kernel_regularizer = regularizer_l2(2e-4),
                      bias_initializer = initializer_random_normal(0.5, 1e-2)) %&gt;%
        layer_max_pooling_2d() %&gt;%
  
        layer_conv_2d(filter=128,
                      kernel_size=c(4,4),
                      activation = "relu",
                      kernel_initializer = initializer_random_normal(0, 1e-2),
                      kernel_regularizer = regularizer_l2(2e-4),
                      bias_initializer = initializer_random_normal(0.5, 1e-2)) %&gt;%
        layer_max_pooling_2d() %&gt;%
  
        layer_conv_2d(filter=256,
                      kernel_size=c(4,4),
                      activation = "relu",
                      kernel_initializer = initializer_random_normal(0, 1e-2),
                      kernel_regularizer = regularizer_l2(2e-4),
                      bias_initializer = initializer_random_normal(0.5, 1e-2)) %&gt;%
  
        layer_flatten() %&gt;%
        layer_dense(4096, 
                    activation = "sigmoid",
                    kernel_initializer = initializer_random_normal(0, 1e-2),
                    kernel_regularizer = regularizer_l2(1e-3),
                    bias_initializer = initializer_random_normal(0.5, 1e-2)) 
  
      encoded_left &lt;- leftInput %&gt;% model
      encoded_right &lt;- rightInput %&gt;% model
  </code></pre>
  
  <p>However, when running the last two lines, I get the following error: </p>
  
  <pre><code>Error in py_call_impl(callable, dots$args, dots$keywords) : 
    AttributeError: 'Model' object has no attribute '_losses'
  
  Detailed traceback: 
    File "/home/rstudio/.virtualenvs/r-tensorflow/lib/python2.7/site-packages/tensorflow/contrib/keras/python/keras/engine/topology.py", line 432, in __call__
      output = super(Layer, self).__call__(inputs, **kwargs)
    File "/home/rstudio/.virtualenvs/r-tensorflow/lib/python2.7/site-packages/tensorflow/python/layers/base.py", line 441, in __call__
      outputs = self.call(inputs, *args, **kwargs)
    File "/home/rstudio/.virtualenvs/r-tensorflow/lib/python2.7/site-packages/tensorflow/contrib/keras/python/keras/models.py", line 560, in call
      return self.model.call(inputs, mask)
    File "/home/rstudio/.virtualenvs/r-tensorflow/lib/python2.7/site-packages/tensorflow/contrib/keras/python/keras/engine/topology.py", line 1743, in call
      output_tensors, _, _ = self.run_internal_graph(inputs, masks)
    File "/home/rstudio/.virtualenvs/r-tensorflow/lib/python2.7/site-packages/tensorflow/contrib/keras/python
  </code></pre>
  
  <p>I have been looking at similar implementations and questions all over StackOverflow, but I could not find a solution. I think I might be missing something really obvious.</p>
  
  <p>Any ideas how to solve this?</p>