This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test and change PredictorExample
- Loading branch information
1 parent
0a3bc8d
commit d286beb
Showing
2 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
scala-package/core/src/test/java/org/apache/mxnet/javaapi/ImageTest.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,50 @@ | ||
package org.apache.mxnet.javaapi; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import java.io.File; | ||
import java.net.URL; | ||
|
||
public class ImageTest { | ||
|
||
private String imLocation; | ||
|
||
private void downloadUrl(String url, String filePath, int maxRetry) throws Exception{ | ||
File tmpFile = new File(filePath); | ||
Boolean success = false; | ||
if (!tmpFile.exists()) { | ||
while (maxRetry > 0 && !success) { | ||
try { | ||
FileUtils.copyURLToFile(new URL(url), tmpFile); | ||
success = true; | ||
} catch(Exception e){ | ||
maxRetry -= 1; | ||
} | ||
} | ||
} else { | ||
success = true; | ||
} | ||
if (!success) throw new Exception("$url Download failed!"); | ||
} | ||
|
||
@BeforeClass | ||
public void downloadFile() throws Exception { | ||
String tempDirPath = System.getProperty("java.io.tmpdir"); | ||
imLocation = tempDirPath + "/inputImages/Pug-Cookie.jpg"; | ||
try { | ||
downloadUrl("https://s3.amazonaws.com/model-server/inputs/Pug-Cookie.jpg", | ||
imLocation, 3); | ||
} catch (Exception e) { | ||
throw e; | ||
} | ||
} | ||
|
||
@Test | ||
public void testImageProcess() { | ||
NDArray nd = Image.imRead(imLocation, 1, true, null); | ||
NDArray nd2 = Image.imResize(nd, 224, 224, null, null); | ||
NDArray cropped = Image.fixedCrop(nd, 0, 0, 224, 224); | ||
Image.toImage(cropped); | ||
} | ||
} |
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