我想运行dl4jexamples/modelimport/ImportDeepMoji.java
,但会引发异常
原因: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
预先感谢
答案 0 :(得分:2)
对于后代,该值为: -Dorg.deeplearning4j.resources.baseurl = $ YOUR_CUSTOM_URL
在IDE或命令行中运行项目时。
您应该可以将值设置为: https://dl4jdata.blob.core.windows.net/
因此,命令行上的系统属性将为: -Dorg.deeplearning4j.resources.baseurl = https://dl4jdata.blob.core.windows.net/
如果对此有疑问,但是这不起作用,请在https://github.com/eclipse/deeplearning4j上提交问题
答案 1 :(得分:0)
正如https://stackoverflow.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
谢谢。
答案 2 :(得分:0)
由于亚当和平的贡献,我解决了这个问题。但是现在在将所需的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结束的过程是否有任何评论?
答案 3 :(得分:0)
尊敬的https://stackoverflow.com/users/5807517/explorer,
第二个问题,错误消息中显示了该问题:
Caused by: java.lang.UnsupportedOperationException: calculateOutputDataTypes() has not been implemented for org.nd4j.linalg.api.ops.impl.reduce.TensorMmul
calculateOutputDataTypes()
功能未实现。
答案 4 :(得分:0)
替换此
String modelUrl = "http://blob.deeplearning4j.org/models/deepmoji.h5";
到
String modelUrl = "https://dl4jdata.blob.core.windows.net/models/deepmoji.h5";
然后它应该可以工作!
答案 5 :(得分:0)
如果仅由于其他示例(例如)而遇到相同的异常Caused by: java.net.UnknownHostException: blob.deeplearning4j.org
时遇到此问题。与deeplearning4j
相关的旧版本(如1.0.0-alpha
)使用的硬编码名称为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.h5
的{{3}}。下载文件,重命名为deepmoji_model.h5并移至缓存位置:C:\Users\user.name\AppData\Local\Temp\dl4j_keras\deepmoji_model.h5