提交 0e7587a9 编写于 作者: B barrierye

update code structure

上级 3461602f
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.paddle.serving.client</groupId>
<artifactId>paddle-serving-sdk-java-examples</artifactId>
<version>0.0.1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
<version>3.8.1</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>my.fully.qualified.class.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<nd4j.backend>nd4j-native</nd4j.backend>
<nd4j.version>1.0.0-beta7</nd4j.version>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<!-- For development use -->
<!-- Include this if you want to try the latest SNAPSHOT version -->
<repositories>
<repository>
<id>oss.sonatype.org-snapshot</id>
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.paddle.serving.client</groupId>
<artifactId>paddle-serving-sdk-java</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>${nd4j.backend}</artifactId>
<version>${nd4j.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
import io.paddle.serving.client.Client;
/**
* Hello world!
*
*/
public class PaddleServingClientExample {
public static void main( String[] args ) {
Client client = new Client();
System.out.println( "Hello World!" );
}
}
...@@ -31,7 +31,7 @@ public class Client { ...@@ -31,7 +31,7 @@ public class Client {
private Set<String> lodTensorSet_; private Set<String> lodTensorSet_;
private Map<String, Integer> feedTensorLen_; private Map<String, Integer> feedTensorLen_;
Client() { public Client() {
channel_ = null; channel_ = null;
blockingStub_ = null; blockingStub_ = null;
futureStub_ = null; futureStub_ = null;
...@@ -45,7 +45,7 @@ public class Client { ...@@ -45,7 +45,7 @@ public class Client {
lodTensorSet_ = null; lodTensorSet_ = null;
feedTensorLen_ = null; feedTensorLen_ = null;
} }
public Boolean setRpcTimeoutMs(int rpc_timeout) throws NullPointerException { public Boolean setRpcTimeoutMs(int rpc_timeout) throws NullPointerException {
if (futureStub_ == null || blockingStub_ == null) { if (futureStub_ == null || blockingStub_ == null) {
throw new NullPointerException("set timeout must be set after connect."); throw new NullPointerException("set timeout must be set after connect.");
...@@ -164,7 +164,6 @@ public class Client { ...@@ -164,7 +164,6 @@ public class Client {
long[] flattened_shape = {-1}; long[] flattened_shape = {-1};
INDArray flattened_list = variable.reshape(flattened_shape); INDArray flattened_list = variable.reshape(flattened_shape);
int v_type = feedTypes_.get(name); int v_type = feedTypes_.get(name);
System.out.println(flattened_list);
NdIndexIterator iter = new NdIndexIterator(flattened_list.shape()); NdIndexIterator iter = new NdIndexIterator(flattened_list.shape());
//System.out.format("name: %s, type: %d\n", name, v_type); //System.out.format("name: %s, type: %d\n", name, v_type);
if (v_type == 0) { // int64 if (v_type == 0) { // int64
...@@ -406,26 +405,27 @@ public class Client { ...@@ -406,26 +405,27 @@ public class Client {
return predict_future; return predict_future;
} }
public static void main( String[] args ) { public static void main( String[] args ) {
/* // DL4J(Deep Learning for Java)Document:
float[] data = {0.0137f, -0.1136f, 0.2553f, -0.0692f, // https://www.bookstack.cn/read/deeplearning4j/bcb48e8eeb38b0c6.md
0.0582f, -0.0727f, -0.1583f, -0.0584f,
0.6283f, 0.4919f, 0.1856f, 0.0795f, -0.0332f}; //float[] data = {0.0137f, -0.1136f, 0.2553f, -0.0692f,
INDArray npdata = Nd4j.createFromArray(data); // 0.0582f, -0.0727f, -0.1583f, -0.0584f,
HashMap<String, INDArray> feed_data // 0.6283f, 0.4919f, 0.1856f, 0.0795f, -0.0332f};
= new HashMap<String, INDArray>() {{ //INDArray npdata = Nd4j.createFromArray(data);
put("x", npdata); //HashMap<String, INDArray> feed_data
}}; // = new HashMap<String, INDArray>() {{
List<String> fetch = Arrays.asList("price"); // put("x", npdata);
*/ //}};
/* //List<String> fetch = Arrays.asList("price");
Map<String, INDArray> fetch_map = client.predict(feed_data, fetch);
for (Map.Entry<String, INDArray> e : fetch_map.entrySet()) { //Map<String, INDArray> fetch_map = client.predict(feed_data, fetch);
System.out.println("Key = " + e.getKey() + ", Value = " + e.getValue()); //for (Map.Entry<String, INDArray> e : fetch_map.entrySet()) {
} // System.out.println("Key = " + e.getKey() + ", Value = " + e.getValue());
*/ //}
//int[] data = {8, 233, 52, 601};
long[] data = {8, 233, 52, 601}; long[] data = {8, 233, 52, 601};
INDArray npdata = Nd4j.createFromArray(data); INDArray npdata = Nd4j.createFromArray(data);
//System.out.println(npdata); //System.out.println(npdata);
...@@ -452,8 +452,8 @@ public class Client { ...@@ -452,8 +452,8 @@ public class Client {
System.out.println("Key = " + e.getKey() + ", Value = " + e.getValue()); System.out.println("Key = " + e.getKey() + ", Value = " + e.getValue());
} }
} }
} }
} }
class PredictFuture { class PredictFuture {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册