Skip to content

Commit

Permalink
Adding Scope Class.
Browse files Browse the repository at this point in the history
  • Loading branch information
arafatkatze committed Mar 3, 2017
1 parent 229916c commit 3b00f69
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/sciruby/tensorflow_c/converter.py
Expand Up @@ -25,5 +25,5 @@ def graphdef_to_pbtxt(filename):

if (os.path.isdir("/home/arafat/Desktop/tensorflow/tensorflow.rb/ext/sciruby/tensorflow_c/pbtxt")):
shutil.rmtree("/home/arafat/Desktop/tensorflow/tensorflow.rb/ext/sciruby/tensorflow_c/pbtxt")
graphdef_to_pbtxt('proto') # here you can write the name of the file to be converted
graphdef_to_pbtxt('track') # here you can write the name of the file to be converted
# and then a new file will be made in pbtxt directory.
12 changes: 12 additions & 0 deletions ext/sciruby/tensorflow_c/example_int64.pb
@@ -0,0 +1,12 @@

;
input1 Placeholder*
dtype0 *
shape: 
;
input2 Placeholder*
dtype0 *
shape: 
&
outputAddinput1input2*
T0 
Binary file added ext/sciruby/tensorflow_c/imaage
Binary file not shown.
5 changes: 5 additions & 0 deletions image/a.rb
Expand Up @@ -30,3 +30,8 @@
# - 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
2 changes: 2 additions & 0 deletions lib/tensorflow.rb
Expand Up @@ -7,3 +7,5 @@
require 'tensorflow/status'
require 'tensorflow/operation'
require 'tensorflow/savedmodel'
require 'tensorflow/scope'
require 'tensorflow/op'
4 changes: 4 additions & 0 deletions lib/tensorflow/op.rb
@@ -0,0 +1,4 @@
# Const adds an operation to graph that produces value as output.
def Const(scope, value)

end
47 changes: 47 additions & 0 deletions lib/tensorflow/scope.rb
@@ -0,0 +1,47 @@
# Scope encapsulates common operation properties when building a Graph.
#
# A Scope object (and its derivates, e.g., obtained from Scope.SubScope)
# act as a builder for graphs. They allow common properties (such as
# a name prefix) to be specified for multiple operations being added
# to the graph.
#
# A Scope object and all its derivates (e.g., obtained from Scope.SubScope)
# are not safe for concurrent use by multiple goroutines.
class Tensorflow::Scope
attr_accessor :graph, :namemap, :namespace
def initialize
graph = Tensorflow::Graph.new
namemap = {}
end

# AddOperation adds the operation to the Graph managed by s.
#
# If there is a name prefix associated with s (such as if s was created
# by a call to SubScope), then this prefix will be applied to the name
# of the operation being added. See also Graph.AddOperation.
def AddOperation(args)
args.name = args.type if args.name == nil
args.name = self.namespace + "/" + args.name if self.namespace == nil
op = graph.AddOperation(args)
end

# SubScope returns a new Scope which will cause all operations added to the
# graph to be namespaced with 'namespace'. If namespace collides with an
# existing namespace within the scope, then a suffix will be added.
def subscope(namespace)
namespace = uniqueName(namespace)
namespace = namespace + "/" + namespace if namespace!=""
end

def uniqueName(name)
count = self.namemap[name]
self.namemap[name]++
return name if count == 0
name = name + "_" + count
return name
end

def opName(typ)
self.namespace+"/"+typ
end
end
70 changes: 70 additions & 0 deletions spec/example_graphs/protobuf.pbtxt
@@ -0,0 +1,70 @@
node {
name: "tensor1"
op: "Placeholder"
attr {
key: "_class"
value {
list {
}
}
}
attr {
key: "dtype"
value {
type: DT_INT64
}
}
attr {
key: "shape"
value {
shape {
}
}
}
}
node {
name: "tensor2"
op: "Placeholder"
attr {
key: "_class"
value {
list {
}
}
}
attr {
key: "dtype"
value {
type: DT_INT64
}
}
attr {
key: "shape"
value {
shape {
}
}
}
}
node {
name: "Addition_of_tensors"
op: "Add"
input: "tensor1"
input: "tensor2"
attr {
key: "T"
value {
type: DT_INT64
}
}
attr {
key: "_class"
value {
list {
}
}
}
}
versions {
producer: 21
}
Binary file added spec/example_graphs/track
Binary file not shown.
18 changes: 18 additions & 0 deletions spec/graph_spec.rb
Expand Up @@ -17,4 +17,22 @@
out_tensor = session.run(hash, [op.output(0)], [])
expect(out_tensor[0]).to match_array([[-4, 4, 9], [10, 6, 10]])
end


it 'Image recognition' do
graph = Tensorflow::Graph.new
graph.read_file(File.dirname(__FILE__)+'/imaage')
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
modeldir = ''
imagefile = File.dirname(__FILE__)+'/inception5h/mysore_palace.jpg'
input1 = Tensorflow::Tensor.new(imagefile, :string)
puts "\ncan read it can read it\n\n\n\n\n"


end
it 'Image recognition' do
graph = Tensorflow::Graph.new

end
end
Binary file added spec/imaage
Binary file not shown.
12 changes: 12 additions & 0 deletions spec/scope_spec.rb
@@ -0,0 +1,12 @@
require 'spec_helper'

describe 'Scope' do
it 'Should Test Sub Scope' do
root = Tensorflow::Scope.new
sub1 = root.subscope("x")
sub2 = root.subscope("x")
sub1a = sub1.subscope("y")
sub2a = sub2.subscope("y")

end
end

0 comments on commit 3b00f69

Please sign in to comment.