1

I would like to run the dl4jexamples/modelimport/ImportDeepMoji.java but it throws an exception

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

how can i address this issue?

this is the complete error log

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

Thanks in advance

Enrico Cortinovis
  • 811
  • 3
  • 8
  • 31
explorer
  • 15
  • 4

6 Answers6

3

Use the system property https://deeplearning4j.org/api/latest/org/deeplearning4j/config/DL4JSystemProperties.html#DL4J_RESOURCES_BASE_URL_PROPERTY for now.

For posterity, the value is: -Dorg.deeplearning4j.resources.baseurl=$YOUR_CUSTOM_URL

when running your project either in your IDE or on command line.

The current revision is here: https://github.com/eclipse/deeplearning4j/blob/da4bf0209b5e2dab36f811603a381ac71f99fe66/deeplearning4j/deeplearning4j-common/src/main/java/org/deeplearning4j/common/resources/DL4JResources.java

You should be able to set the value to: https://dl4jdata.blob.core.windows.net/

So the system property on the command line will be: -Dorg.deeplearning4j.resources.baseurl=https://dl4jdata.blob.core.windows.net/

If you have issues with this and this doesn't work, please file an issue at https://github.com/eclipse/deeplearning4j

Adam Gibson
  • 3,055
  • 1
  • 10
  • 12
  • //String modelUrl = "http://blob.deeplearning4j.org/models/deepmoji.h5"; DL4JResources.setBaseDownloadURL("https://dl4jdata.blob.core.windows.net/"); String modelUrl =DL4JResources.getBaseDownloadURL(); String downloadPath = DATA_PATH + "deepmoji_model.h5"; – explorer Nov 29 '19 at 08:26
  • but still i get error like this in Intellij Downloading model to C:\Users\BAP1\AppData\Local\Temp\dl4j_keras\deepmoji_model.h5 Exception in thread "main" java.io.IOException: Server returned HTTP response code: 400 for URL: https://dl4jdata.blob.core.windows.net/ at java.base/sun.net.www.protocol.http.HttpURLConnection – explorer Nov 29 '19 at 08:28
  • i think i need exact url address for deepmoji_model.h5 file. i.e : https://dl4jdata.blob.core.windows.net/deepmoji_model.h5 is a correct url address? if it is not what s the full path now? Thanks – explorer Nov 29 '19 at 08:38
  • The URL you're setting isn't valid. It needs to be literally a full URL. You're not using any prefixes. Please follow the *exact* instructions in my answer. – Adam Gibson Nov 30 '19 at 10:28
  • I used https://dl4jdata.blob.core.windows.net/deepmoji_model.h5 this url in the code but still it seems there is not deepmoji_model.h5 file in the https://dl4jdata.blob.core.windows.net/ base url. Could you write me the exact link of the deepmoji_model.h5 so that i download it my pc by chrome or iexplorer browser? – explorer Dec 01 '19 at 12:04
  • I used "https://"dl4jdata.blob.core.windows.net/deepmoji_model.h5 this url in the code but still it seems there is not deepmoji_model.h5 file in the dl4jdata.blob.core.windows.net base url. Could you write me the exact link of the deepmoji_model.h5 so that i can download it to my pc by chrome or iexplorer browser? – explorer Dec 01 '19 at 12:05
1

As pointed out by https://stackoverflow.com/users/5131255/adam-gibson, I added

import org.deeplearning4j.common.resources.DL4JResources;

and

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

in my java project, and exception problem is fixed.

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

Thank You.

Ping Chia
  • 61
  • 4
  • ok thanks you very much as you are mentioned the exact url should be String modelUrl = "https://dl4jdata.blob.core.windows.net/models/deepmoji.h5"; – explorer Dec 04 '19 at 07:44
1

Replace this

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

to

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

Then it should work !

Blaze Lim
  • 26
  • 1
0

I solved the issue thanks to Adam's and Ping's contributions. But now i get following exception after download the required h5 files form the server to the local machine.

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

Process finished with exit code 1 Is there any comments?

explorer
  • 15
  • 4
0

Dear https://stackoverflow.com/users/5807517/explorer,

To your second question, the problem is shown in the error message:

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

The calculateOutputDataTypes() function is not implemented.

Ping Chia
  • 61
  • 4
0

If you came to this question with getting the same exception Caused by: java.net.UnknownHostException: blob.deeplearning4j.org just because of the other examples, eg. related to deeplearning4j with old versions like 1.0.0-alpha that uses pretrained models with hardcoded name tiny-yolo-voc_dl4j_inference.v1.zip, follow these steps:

  • Create a folder under your home folder (eg. for windoz C:\Users\user.name\.deeplearning4j)
  • Download the file: tiny-yolo-voc_dl4j_inference.v1.zip and put the file into this folder
  • Run the code again

ZooModel looks for pretrained model cached at this location instead of going to 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());
        }

For the ImportDeepMoji.java here is the download link for model file deepmoji.h5. Download the file, rename to deepmoji_model.h5 and move to cache location: C:\Users\user.name\AppData\Local\Temp\dl4j_keras\deepmoji_model.h5

M.Uluer
  • 65
  • 1
  • 7