This repository has been archived by the owner on Apr 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/h2oai/steam into deepwater
- Loading branch information
Showing
13 changed files
with
234 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
rm -f example.war | ||
|
||
curl -X POST \ | ||
--form [email protected] \ | ||
--form [email protected] \ | ||
localhost:55000/makewar > example.war | ||
|
||
if [ -s example.war ] | ||
then | ||
echo "Created example.war" | ||
echo "Run with run-example.sh" | ||
else | ||
echo "Failed to build example.war" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
java -Dorg.slf4j.simpleLogger.defaultLogLevel=DEBUG -jar ../jetty-runner-8.1.14.v20131031.jar --port 55001 example.war |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "Starting prediction service on port 55001" | ||
echo "" | ||
|
||
java -jar ../jetty-runner-8.1.14.v20131031.jar --port 55001 example.war | ||
|
26 changes: 26 additions & 0 deletions
26
prediction-service-builder/examples/deepwater/test-example.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
|
||
curl -X POST \ | ||
--form [email protected] \ | ||
--form abc=def \ | ||
--form data='{Dest: SFO, Orig: JFK}' \ | ||
http://localhost:55001/predictbinary | ||
|
||
echo "test1 bird" | ||
|
||
curl -X POST \ | ||
--form [email protected] \ | ||
http://localhost:55001/predictbinary | ||
|
||
echo "test2 dog" | ||
|
||
curl -X POST \ | ||
--form [email protected] \ | ||
http://localhost:55001/predictbinary | ||
|
||
echo "url of dog" | ||
|
||
#curl -X POST \ | ||
#--form C1="https://c1.staticflickr.com/1/225/515776742_bce2e6dbea_d.jpg" \ | ||
#http://localhost:55001/predictbinary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
prediction-service-builder/src/main/webapp/extra/src/PredictBinaryServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import hex.genmodel.*; | ||
import hex.genmodel.easy.*; | ||
import hex.genmodel.easy.prediction.AbstractPrediction; | ||
import org.apache.commons.fileupload.FileItem; | ||
import org.apache.commons.fileupload.disk.DiskFileItemFactory; | ||
import org.apache.commons.fileupload.servlet.ServletFileUpload; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.io.IOUtils; | ||
import org.slf4j.Logger; | ||
|
||
import javax.servlet.ServletConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.File; | ||
import java.io.InputStream; | ||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
import java.util.List; | ||
|
||
public class PredictBinaryServlet extends HttpServlet { | ||
private final Logger logger = Logging.getLogger(this.getClass()); | ||
|
||
private static final Gson gson = new GsonBuilder().serializeSpecialFloatingPointValues().create(); | ||
|
||
private static GenModel rawModel = null; | ||
private static EasyPredictModelWrapper model = null; | ||
private static Transform transform = ServletUtil.transform; | ||
|
||
private File servletPath = null; | ||
|
||
public void init(ServletConfig servletConfig) throws ServletException { | ||
super.init(servletConfig); | ||
try { | ||
servletPath = new File(servletConfig.getServletContext().getResource("/").getPath()); | ||
logger.debug("servletPath {}", servletPath); | ||
ServletUtil.loadModels(servletPath); | ||
model = ServletUtil.model; | ||
logger.debug("model {}", model); | ||
} | ||
catch (MalformedURLException e) { | ||
logger.error("init failed", e); | ||
} | ||
} | ||
|
||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
response.setHeader("Access-Control-Allow-Origin", "*"); | ||
long start = System.nanoTime(); | ||
File tmpDir = null; | ||
try { | ||
if (model == null) | ||
throw new Exception("No predictor model"); | ||
|
||
// fill row with parameters, some of which are binary, like images | ||
RowData row = new RowData(); | ||
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); | ||
for (FileItem i : items) { | ||
String field = i.getFieldName(); | ||
String value = i.getString(); | ||
if (field.startsWith("binary_")) { | ||
String binFieldName = field.substring("binary_".length()); | ||
if (binFieldName == null || binFieldName.length() == 0) | ||
throw new Exception("empty binary field name for " + field); | ||
InputStream inputStream = i.getInputStream(); | ||
if (inputStream == null) | ||
throw new Exception("null input stream for " + field); | ||
byte[] bindata = IOUtils.toByteArray(inputStream); | ||
if (bindata.length == 0) | ||
throw new Exception("empty binary field value for " + field); | ||
logger.debug("binary field {} size {}", binFieldName, bindata.length); | ||
row.put(binFieldName, bindata); | ||
} | ||
else if (field.equals("data")) { | ||
RowData r = gson.fromJson(value, ServletUtil.ROW_DATA_TYPE); | ||
logger.debug("data {}", r); | ||
row.putAll(r); | ||
} | ||
else { | ||
logger.debug("text field {} value {}", field, value); | ||
row.put(field, value); | ||
} | ||
} | ||
// now have parameters in row | ||
logger.debug("row size {} keys {}", row.size(), row.keySet()); | ||
|
||
AbstractPrediction pr; | ||
String prJson; | ||
|
||
if (transform == null) { // no jar transformation | ||
logger.debug("no transformation of input data"); | ||
} | ||
else { | ||
logger.debug("transformation of input data"); | ||
} | ||
|
||
if (row != null) { | ||
// do the prediction | ||
pr = ServletUtil.predict(row); | ||
|
||
// assemble json result | ||
prJson = gson.toJson(pr); | ||
logger.debug(prJson); | ||
|
||
// Emit the prediction to the servlet response. | ||
response.getWriter().write(prJson); | ||
} | ||
|
||
response.setStatus(HttpServletResponse.SC_OK); | ||
} | ||
catch (Exception e) { | ||
// Prediction failed. | ||
logger.error("post failed", e); | ||
response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE, e.getMessage()); | ||
} | ||
finally { | ||
// if the temp directory is still there we delete it | ||
if (tmpDir != null && tmpDir.exists()) { | ||
try { | ||
FileUtils.deleteDirectory(tmpDir); | ||
} | ||
catch (IOException e) { | ||
logger.error("Can't delete tmp directory"); | ||
} | ||
} | ||
} | ||
long done = System.nanoTime(); | ||
ServletUtil.postTimes.add(start, done); | ||
logger.debug("Post time {}", ServletUtil.postTimes); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
scoring-service-builder/examples/image-classifier/test-example.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
curl -X POST \ | ||
--form [email protected] \ | ||
--form abc=def \ | ||
--form data='{Dest: SFO, Orig: JFK}' \ | ||
http://localhost:55001/predictbinary | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
java -Dorg.slf4j.simpleLogger.defaultLogLevel=DEBUG -jar ../jetty-runner-8.1.14.v20131031.jar --port 55001 example.war |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "Starting prediction service on port 55001" | ||
echo "" | ||
|
||
java -jar ../jetty-runner-8.1.14.v20131031.jar --port 55001 example.war | ||
|