forked from somaticio/tensorflow.rb
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making linter changes and removing un necessary files.
Squashed commit of the following: commit 1802f8a Author: Arafatk <arafat.da.khan@gmail.com> Date: Sat Mar 4 23:47:21 2017 +0530 Removing unnecessary file writing spec. commit 41dd55f Author: Arafatk <arafat.da.khan@gmail.com> Date: Sat Mar 4 23:40:13 2017 +0530 Adding Linter Changes to Specs. commit 23c6833 Author: Arafatk <arafat.da.khan@gmail.com> Date: Sat Mar 4 23:36:48 2017 +0530 Adding Linter changes.
- Loading branch information
1 parent
d8bcdc3
commit ecf1954
Showing
33 changed files
with
595 additions
and
1,813 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,30 +1,43 @@ | ||
# This file is useful for reading the contents of the ops generated by ruby. | ||
# You can read any graph defination in pb/pbtxt format generated by ruby | ||
# or by python and then convert it back and forth from human readable to binary format. | ||
# or by python and then convert it back and forth from human readable to | ||
# binary format. | ||
|
||
import tensorflow as tf | ||
import shutil, os | ||
import shutil | ||
import os | ||
from google.protobuf import text_format | ||
from tensorflow.python.platform import gfile | ||
|
||
# Converts protobuf file from pbtxt to binary wire format | ||
|
||
|
||
def pbtxt_to_graphdef(filename): | ||
with open(filename, 'r') as f: | ||
graph_def = tf.GraphDef() | ||
file_content = f.read() | ||
text_format.Merge(file_content, graph_def) | ||
tf.import_graph_def(graph_def, name='') | ||
tf.train.write_graph(graph_def, 'pbtxt/', 'protobuf.pb', as_text=False) | ||
with open(filename, 'r') as f: | ||
graph_def = tf.GraphDef() | ||
file_content = f.read() | ||
text_format.Merge(file_content, graph_def) | ||
tf.import_graph_def(graph_def, name='') | ||
tf.train.write_graph(graph_def, 'pbtxt/', 'protobuf.pb', as_text=False) | ||
|
||
# Converts protobuf file from binary wire format to pbtxt | ||
|
||
|
||
def graphdef_to_pbtxt(filename): | ||
with gfile.FastGFile(filename,'rb') as f: | ||
graph_defe = tf.GraphDef() | ||
graph_defe.ParseFromString(f.read()) | ||
tf.import_graph_def(graph_defe, name='') | ||
# tf.summary.FileWriter('/home/arafat/Desktop/test', graph_def = graph_defe) | ||
tf.train.write_graph(graph_defe, 'pbtxt/', 'protobuf.pbtxt', as_text=True) | ||
return | ||
|
||
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('abc') # here you can write the name of the file to be converted | ||
# and then a new file will be made in pbtxt directory. | ||
with gfile.FastGFile(filename, 'rb') as f: | ||
graph_defe = tf.GraphDef() | ||
graph_defe.ParseFromString(f.read()) | ||
tf.import_graph_def(graph_defe, name='') | ||
tf.train.write_graph(graph_defe, 'pbtxt/', | ||
'protobuf.pbtxt', as_text=True) | ||
return | ||
|
||
|
||
# A simple check to remove the directory if its already present. | ||
directory = "/home/arafat/Desktop/tensorflow/tensorflow.rb/ext/sciruby/tensorflow_c/pbtxt" | ||
if (os.path.isdir(directory)): | ||
shutil.rmtree(directory) | ||
|
||
# Name of the file to be converted | ||
filename = 'int64_test.pb' | ||
graphdef_to_pbtxt(filename) |
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
Binary file not shown.
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
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
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 |
---|---|---|
@@ -1,65 +1,65 @@ | ||
class Tensorflow::Output | ||
attr_accessor :index, :operation | ||
def c | ||
Tensorflow.input(operation.c, index) | ||
end | ||
attr_accessor :index, :operation | ||
def c | ||
Tensorflow.input(operation.c, index) | ||
end | ||
|
||
def dataType | ||
Tensorflow::TF_OperationOutputType(c()) | ||
end | ||
def dataType | ||
Tensorflow::TF_OperationOutputType(c) | ||
end | ||
end | ||
|
||
# Operation that has been added to the graph. | ||
class Tensorflow::Operation | ||
attr_accessor :c, :g | ||
# @!attribute c | ||
# contains the graph representation. | ||
# @!attribute g | ||
# A reference to the Graph to prevent it from being GCed while the Operation is still alive. | ||
attr_accessor :c, :g | ||
# @!attribute c | ||
# contains the graph representation. | ||
# @!attribute g | ||
# A reference to the Graph to prevent it from being GCed while the Operation is still alive. | ||
|
||
def initialize(c_representation, graph) | ||
self.c = c_representation | ||
self.g = graph | ||
end | ||
def initialize(c_representation, graph) | ||
self.c = c_representation | ||
self.g = graph | ||
end | ||
|
||
def name | ||
# May need to convert this to a ruby string | ||
Tensorflow::TF_OperationName(self.c) | ||
end | ||
def name | ||
# May need to convert this to a ruby string | ||
Tensorflow::TF_OperationName(c) | ||
end | ||
|
||
def type | ||
# May need to convert this to a ruby string | ||
Tensorflow::TF_OperationOpType(self.c) | ||
end | ||
def type | ||
# May need to convert this to a ruby string | ||
Tensorflow::TF_OperationOpType(c) | ||
end | ||
|
||
def num_outputs | ||
# May need to convert this to ruby int | ||
Tensorflow::TF_OperationNumOutputs(self.c) | ||
end | ||
def num_outputs | ||
# May need to convert this to ruby int | ||
Tensorflow::TF_OperationNumOutputs(c) | ||
end | ||
|
||
# OutputListSize returns the size of the list of Outputs that is produced by a | ||
# named output of op. | ||
# | ||
# An Operation has multiple named outputs, each of which produces either | ||
# a single tensor or a list of tensors. This method returns the size of | ||
# the list of tensors for a specific output of the operation, identified | ||
# by its name. | ||
def output_list_size(output) | ||
cname = CString(output) | ||
status = Tensorflow::Status.new | ||
Tensorflow::TF_OperationOutputListLength(self.c, cname, status.c) | ||
end | ||
# OutputListSize returns the size of the list of Outputs that is produced by a | ||
# named output of op. | ||
# | ||
# An Operation has multiple named outputs, each of which produces either | ||
# a single tensor or a list of tensors. This method returns the size of | ||
# the list of tensors for a specific output of the operation, identified | ||
# by its name. | ||
def output_list_size(output) | ||
cname = CString(output) | ||
status = Tensorflow::Status.new | ||
Tensorflow::TF_OperationOutputListLength(c, cname, status.c) | ||
end | ||
|
||
def output(i) | ||
out = Tensorflow::Output.new | ||
out.operation = self | ||
out.index = i | ||
out | ||
end | ||
def output(i) | ||
out = Tensorflow::Output.new | ||
out.operation = self | ||
out.index = i | ||
out | ||
end | ||
end | ||
|
||
class Tensorflow::Input | ||
attr_accessor :Index, :Operations | ||
def initialize | ||
end | ||
attr_accessor :Index, :Operations | ||
def initialize | ||
end | ||
end |
Oops, something went wrong.