File tree 1 file changed +35
-0
lines changed 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+ # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ==============================================================================
16
+ """jpeg2json.py: Converts a JPEG image into a json request to CloudML.
17
+
18
+ Usage:
19
+ python jpeg2json.py 002s_C6_ImagerDefaults_9.jpg > request.json
20
+
21
+ See:
22
+ https://cloud.google.com/ml-engine/docs/concepts/prediction-overview#online_prediction_input_data
23
+ """
24
+
25
+ import base64
26
+ import sys
27
+
28
+
29
+ def to_json (data ):
30
+ return '{"image_bytes":{"b64": "%s"}}' % base64 .b64encode (data )
31
+
32
+
33
+ if __name__ == '__main__' :
34
+ file = open (sys .argv [1 ]) if len (sys .argv ) > 1 else sys .stdin
35
+ print (to_json (file .read ()))
You can’t perform that action at this time.
0 commit comments