forked from somaticio/tensorflow.rb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
a.rb
37 lines (35 loc) · 1.6 KB
/
a.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'tensorflow'
# An example for using the TensorFlow Go API for image recognition
# using a pre-trained inception model (http://arxiv.org/abs/1512.00567).
#
# Sample usage: <program> -dir=/tmp/modeldir -image=/path/to/some/jpeg
#
# The pre-trained model takes input in the form of a 4-dimensional
# tensor with shape [ BATCH_SIZE, IMAGE_HEIGHT, IMAGE_WIDTH, 3 ],
# where:
# - BATCH_SIZE allows for inference of multiple images in one pass through the graph
# - IMAGE_HEIGHT is the height of the images on which the model was trained
# - IMAGE_WIDTH is the width of the images on which the model was trained
# - 3 is the (R, G, B) values of the pixel colors represented as a float.
#
# And produces as output a vector with shape [ NUM_LABELS ].
# output[i] is the probability that the input image was recognized as
# having the i-th label.
#
# A separate file contains a list of string labels corresponding to the
# integer indices of the output.
#
# This example:
# - Loads the serialized representation of the pre-trained model into a Graph
# - Creates a Session to execute operations on the Graph
# - Converts an image file to a Tensor to provide as input to a Session run
# - Executes the Session and prints out the label with the highest probability
#
# To convert an image file to a Tensor suitable for input to the Inception model,
# this example:
# - Constructs another TensorFlow graph to normalize the image into a
# form suitable for the model (for example, resizing the image)
# - Creates an executes a Session to obtain a Tensor in this normalized form.
modeldir = ''
imagefile = ''
graph = TensorFlow::Graph.new