【问题标题】:Trouble downloading Keras resnet50 model in R在 R 中下载 Keras resnet50 模型时遇到问题
【发布时间】:2019-03-05 18:59:57
【问题描述】:

我正在尝试使用以下代码从 R 中的 Keras 下载 ResNet50 模型

model_resnet <- application_resnet50(weights = 'imagenet')

代码运行了几秒钟并且没有给出任何错误,但是它不像其他 Keras 模型那样是一个“模型”类,它保存为以下类:

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

我无法从中预测任何内容,也无法打印它的摘要或任何内容。如果我尝试从 R 中的 ?application_resnet50 帮助页面运行示例代码,我也会遇到同样的问题。

有人知道这是什么意思吗?

R 3.5.1, Keras 2.2.2, TensorFlow 1.11.0

【问题讨论】:

  • 我想知道我们是否不是这个问题的某种变体stackoverflow

标签: r tensorflow keras rstudio


【解决方案1】:

我们遵循 tensorflow rstudio 的代码并使用 R 3.5.1、Keras 2.2.2、Tensorflow 1.11.0

基本上,它按预期工作。代码运行了几秒钟,如果一切顺利,你最终会得到

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

正如它所说,它是一个模型。如果事情不顺利,这就是正在尝试的,这里是网络故障:

    > 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

然后是作品:

    > 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> 

下一部分取决于那些/那个大象 jpeg 来自或来自哪里, 从上面的链接中不清楚,尽管可能来自 image-net.org。 无论如何,如果你的工作目录中没有“elephant.jpg”,你会得到:

    > 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' 

获取一些大象 jpeg 并继续按照示例进行操作并玩得开心。

【讨论】:

  • 谢谢克里斯。我有一张大象图片并对其进行了预处理。那不是我得到错误的地方。我收到预测()的以下错误。 > preds % predict(x) Error in UseMethod("predict") : 没有适用于 'predict' 的方法应用于“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' )"
  • 我去找一头大象,看看能不能繁殖。
猜你喜欢
  • 2021-10-31
  • 1970-01-01
  • 1970-01-01
  • 2018-04-24
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多