0

I'm trying to download the ResNet50 model from Keras in R using the following code

model_resnet <- application_resnet50(weights = 'imagenet')

The code runs for a few seconds and doesn't give any error, however rather than being a 'Model' class like other Keras models, it saves as the following class:

<tensorflow.python.keras.engine.training.Model>

I can't predict anything from it or print it's summary or anything. I have the same issue if I try and run the example code from the ?application_resnet50 help page in R.

Does anyone know what this means?

R 3.5.1, Keras 2.2.2, Tensorflow 1.11.0

Tadro
  • 61
  • 1
  • 3
  • I'm wondering if we're not is some variant of this problem [stackoverflow](https://stackoverflow.com/questions/38623624/usemethodpredict-no-applicable-method-for-predict-applied-to-an-object-o) – Chris Oct 09 '18 at 14:36

1 Answers1

0

We're following the code from tensorflow rstudio and using R 3.5.1, Keras 2.2.2, Tensorflow 1.11.0

Basically, it is working as expected. The code runs for a few seconds and if all goes right, you end up with

<tensorflow.python.keras.engine.training.Model>

It is a Model, as it says. If things don't go right, this is what is being attempted, and here a network failure:

    > library(keras)
    > library(tensorflow)
    > model_resnet50 <- application_resnet50()
    Error in py_call_impl(callable, dots$args, dots$keywords) : 
    RemoteDisconnected: Remote end closed connection without response

Then is works:

    > model_resnet50 <- application_resnet50(weights = 'imagenet')
    Downloading data from https://github.com/fchollet/deep-learning- models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels.h5
    Downloading data from https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels.h5
    102858752/102853048 [==============================] - 14s 0us/step
    2018-09-30 18:20:12.316814: I 
    tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports 
    instructions that this TensorFlow binary was not compiled to use: 
    SSE4.1 SSE4.2
    > model_resnet50
    <tensorflow.python.keras.engine.training.Model> 

The next part depends on where those/that elephant jpeg are or come from, it isn't clear from the link above, though probably from image-net.org. Anyway, absent an "elephant.jpg" in your working directory, you get:

    > img_path <- "elephant.jpg"
    > img <- image_load(img_path, target_size = c(224,224))
    Error in py_call_impl(callable, dots$args, dots$keywords) : 
    FileNotFoundError: [Errno 2] No such file or directory: 
    'elephant.jpg' 

Get some elephant jpegs and continue following the examples and have fun.

Chris
  • 1,647
  • 1
  • 18
  • 25
  • Thanks Chris. I've got an elephant pic and pre-processed it. That's not where I'm getting the error. I'm getting the following error with predict(). > preds <- model %>% predict(x) Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "c('tensorflow.python.keras.engine.training.Model', 'tensorflow.python.keras.engine.network.Network', 'tensorflow.python.keras.engine.base_layer.Layer', 'tensorflow.python.training.checkpointable.base.CheckpointableBase', 'python.builtin.object')" – Tadro Oct 01 '18 at 02:34
  • I'll find an elephant and see if I can reproduce. – Chris Oct 06 '18 at 11:28