由以下原因引起:java.net.UnknownHostException: blob.deeplearning4j.org deeplearning4j 问题

Caused by: java.net.UnknownHostException: blob.deeplearning4j.org problem with deeplearning4j

我想 运行 dl4jexamples/modelimport/ImportDeepMoji.java 但它抛出异常

Caused by: java.net.UnknownHostException: blob.deeplearning4j.org

我该如何解决这个问题?

这是完整的错误日志

Downloading model to C:\Users\DELLLA~1\AppData\Local\Temp\dl4j_keras\deepmoji_model.h5
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:66)
Caused by: java.net.UnknownHostException: blob.deeplearning4j.org
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at java.net.Socket.connect(Socket.java:538)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
    at sun.net.www.http.HttpClient.New(HttpClient.java:308)
    at sun.net.www.http.HttpClient.New(HttpClient.java:326)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1202)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:966)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1546)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
    at java.net.URL.openStream(URL.java:1045)
    at org.apache.commons.io.FileUtils.copyURLToFile(FileUtils.java:1478)
    at org.deeplearning4j.examples.modelimport.keras.ImportDeepMoji.main(ImportDeepMoji.java:57)
    ... 5 more

提前致谢

暂时使用系统属性https://deeplearning4j.org/api/latest/org/deeplearning4j/config/DL4JSystemProperties.html#DL4J_RESOURCES_BASE_URL_PROPERTY

对于子孙后代来说,价值是: -Dorg.deeplearning4j.resources.baseurl=$YOUR_CUSTOM_URL

当 运行 您的项目在 IDE 或命令行中时。

当前版本在这里:https://github.com/eclipse/deeplearning4j/blob/da4bf0209b5e2dab36f811603a381ac71f99fe66/deeplearning4j/deeplearning4j-common/src/main/java/org/deeplearning4j/common/resources/DL4JResources.java

您应该能够将值设置为: https://dl4jdata.blob.core.windows.net/

因此命令行上的系统属性将是: -Dorg.deeplearning4j.resources.baseurl=https://dl4jdata.blob.core.windows.net/

如果您对此有任何疑问并且不起作用,请在 https://github.com/eclipse/deeplearning4j

提交问题

正如https://whosebug.com/users/5131255/adam-gibson所指出的,我添加了

import org.deeplearning4j.common.resources.DL4JResources;

DL4JResources.setBaseDownloadURL("https://dl4jdata.blob.core.windows.net/");

在我的java项目中,异常问题已修复。

Caused by: java.net.UnknownHostException: blob.deeplearning4j.org

谢谢。

由于 Adam 和 Ping 的贡献,我解决了这个问题。但是现在我在将所需的 h5 文件从服务器下载到本地计算机后出现以下异常。

Downloading model to C:\Users\DELLLA~1\AppData\Local\Temp\dl4j_keras\deepmoji_model.h5
Download complete
o.d.n.m.k.l.e.KerasEmbedding - Masking in keras and DL4J work differently. We do not completely support mask_zero flag on Embedding layers. Zero Masking for the Embedding layer only works with unidirectional LSTM for now. If you want to have this behaviour for your imported model in DL4J, apply masking as a pre-processing step to your input.See https://deeplearning4j.org/usingrnns#masking for more on this.
o.d.n.m.k.KerasModel - If enforceTrainingConfig is true, a training configuration object has to be provided. Usually the only practical way to do this is to store your keras model with `model.save('model_path.h5'. If you store model config and weights separately no training configuration is attached.
o.n.l.f.Nd4jBackend - Loaded [CpuBackend] backend
o.n.n.NativeOpsHolder - Number of threads used for OpenMP: 6
o.n.n.Nd4jBlas - Number of threads used for OpenMP BLAS: 6
o.n.l.a.o.e.DefaultOpExecutioner - Backend used: [CPU]; OS: [Windows 8.1]
o.n.l.a.o.e.DefaultOpExecutioner - Cores: [24]; Memory: [3,5GB];
o.n.l.a.o.e.DefaultOpExecutioner - Blas vendor: [MKL]
o.d.n.g.ComputationGraph - Starting ComputationGraph with WorkspaceModes set to [training: ENABLED; inference: ENABLED], cacheMode set to [NONE]
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:66)
Caused by: java.lang.UnsupportedOperationException: calculateOutputDataTypes() has not been implemented for org.nd4j.linalg.api.ops.impl.reduce.TensorMmul
    at org.nd4j.autodiff.functions.DifferentialFunction.calculateOutputDataTypes(DifferentialFunction.java:804)
    at org.nd4j.autodiff.samediff.SameDiff.generateOutputVariableForOp(SameDiff.java:4351)
    at org.nd4j.linalg.api.ops.DynamicCustomOp.outputVariables(DynamicCustomOp.java:221)
    at org.nd4j.linalg.api.ops.DynamicCustomOp.outputVariables(DynamicCustomOp.java:204)
    at org.nd4j.autodiff.functions.DifferentialFunction.outputVariable(DifferentialFunction.java:478)
    at org.nd4j.autodiff.functions.DifferentialFunctionFactory.tensorMmul(DifferentialFunctionFactory.java:1875)
    at org.nd4j.autodiff.samediff.ops.SDBaseOps.tensorMmul(SDBaseOps.java:2823)
    at org.nd4j.autodiff.samediff.ops.SDBaseOps.tensorMmul(SDBaseOps.java:2809)
    at org.deeplearning4j.examples.modelimport.keras.DeepMojiAttentionLayer.defineLayer(DeepMojiAttentionLayer.java:86)
    at org.deeplearning4j.nn.layers.samediff.SameDiffLayer.doInit(SameDiffLayer.java:282)
    at org.deeplearning4j.nn.layers.samediff.SameDiffLayer.activate(SameDiffLayer.java:85)
    at org.deeplearning4j.nn.graph.vertex.impl.LayerVertex.doForward(LayerVertex.java:111)
    at org.deeplearning4j.nn.graph.ComputationGraph.outputOfLayersDetached(ComputationGraph.java:2379)
    at org.deeplearning4j.nn.graph.ComputationGraph.output(ComputationGraph.java:1740)
    at org.deeplearning4j.nn.graph.ComputationGraph.output(ComputationGraph.java:1696)
    at org.deeplearning4j.nn.graph.ComputationGraph.output(ComputationGraph.java:1626)
    at org.deeplearning4j.examples.modelimport.keras.ImportDeepMoji.main(ImportDeepMoji.java:64)
    ... 5 more

进程已完成,退出代码为 1 有任何意见吗?

亲爱的https://whosebug.com/users/5807517/explorer,

关于你的第二个问题,问题如错误信息所示:

Caused by: java.lang.UnsupportedOperationException: calculateOutputDataTypes() has not been implemented for org.nd4j.linalg.api.ops.impl.reduce.TensorMmul

calculateOutputDataTypes()功能未实现。

替换此

String modelUrl = "http://blob.deeplearning4j.org/models/deepmoji.h5";

String modelUrl = "https://dl4jdata.blob.core.windows.net/models/deepmoji.h5";

那么应该可以了!

如果你遇到这个问题并得到相同的异常 Caused by: java.net.UnknownHostException: blob.deeplearning4j.org 只是因为其他例子,例如。与 deeplearning4j 相关的旧版本,如 1.0.0-alpha 使用硬编码名称 tiny-yolo-voc_dl4j_inference.v1.zip 的预训练模型,请按照以下步骤操作:

  • 在您的主文件夹下创建一个文件夹(例如,对于 windoz C:\Users\user.name\.deeplearning4j)
  • 下载文件:tiny-yolo-voc_dl4j_inference.v1.zip并将文件放入此文件夹
  • 运行再次代码

ZooModel 查找缓存在此位置的预训练模型,而不是转到 blob.deeplearning4j.org

        if (!cachedFile.exists()) {
            log.info("Downloading model to " + cachedFile.toString());
            FileUtils.copyURLToFile(new URL(remoteUrl), cachedFile);
        } else {
            log.info("Using cached model at " + cachedFile.toString());
        }

对于 ImportDeepMoji.java 这里是模型文件 deepmoji.h5download link。下载文件,重命名为 deepmoji_model.h5 并移动到缓存位置:C:\Users\user.name\AppData\Local\Temp\dl4j_keras\deepmoji_model.h5