This repository was archived by the owner on Sep 17, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
src/main/scala/tensorflow Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 11package tensorflow
22
3+ import java .awt .image .DataBufferByte
4+ import java .io .{BufferedInputStream , ByteArrayOutputStream }
5+ import java .net .URL
36import java .nio .file .{Files , Paths }
7+ import javax .imageio .ImageIO
48
59import tensorflow .model .InceptionV3
610
@@ -9,7 +13,23 @@ object TensorFlowExample {
913 def main (args : Array [String ]) {
1014 // image file
1115 val jpgFile = args.headOption.getOrElse(" cropped_panda.jpg" )
12- val jpgAsBytes = Files .readAllBytes(Paths .get(jpgFile))
16+ val jpgAsBytes = jpgFile match {
17+ case urlString if urlString.startsWith(" http" ) =>
18+ val url = new URL (urlString)
19+ val in = new BufferedInputStream (url.openStream())
20+ val out = new ByteArrayOutputStream ()
21+ val buf = new Array [Byte ](1024 )
22+ var n = in.read(buf)
23+ while (n != - 1 ) {
24+ out.write(buf, 0 , n)
25+ n = in.read(buf)
26+ }
27+ val bytes = out.toByteArray
28+ out.close()
29+ in.close()
30+ bytes
31+ case file => Files .readAllBytes(Paths .get(file))
32+ }
1333
1434 // define the model
1535 val model = new InceptionV3 (" model" )
You can’t perform that action at this time.
0 commit comments