Skip to content

Instantly share code, notes, and snippets.

View arafatkatze's full-sized avatar
💭
Lover of life and all things beautiful

Ara arafatkatze

💭
Lover of life and all things beautiful
View GitHub Profile
# 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.
import tensorflow as tf
from google.protobuf import text_format
from tensorflow.python.platform import gfile
def pbtxt_to_graphdef(filename):
with open(filename, 'r') as f:
The top five results are
golden retriever
0.7964490652084351
Labrador retriever
0.0944252461194992
kuvasz
0.03383997827768326
clumber
0.005355054046958685
Great Pyrenees
import tensorflow as tf
from tensorflow.python.platform import gfile
import sys
def converter(filename):
with gfile.FastGFile(filename,'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
tf.import_graph_def(graph_def, name='')
tf.train.write_graph(graph_def, 'pbtxt/', 'protobuf.pbtxt', as_text=True)
require 'tensorflow'
graph_def = Tensorflow::GraphDef.new
node_a = Tensorflow::NodeDef.new(name: "Placeholder", op: "Placeholder", attr: [])
node_a.attr.push(Tensorflow::NodeDef::AttrEntry.new(key: "dtype" ,value: Tensorflow::AttrValue.new(type: 1)))
node_a.attr.push(Tensorflow::NodeDef::AttrEntry.new(key: "shape" , value: Tensorflow::AttrValue.new(shape: Tensorflow::TensorShapeProto.new(dim: [Tensorflow::TensorShapeProto::Dim.new(size: 2)]))))
graph_def.node.push(node_a)
node_b = Tensorflow::NodeDef.new(name: "Placeholder_1", op: "Placeholder", attr: [])
node_b.attr.push(Tensorflow::NodeDef::AttrEntry.new(key: "dtype" ,value: Tensorflow::AttrValue.new(type: 1)))
node_b.attr.push(Tensorflow::NodeDef::AttrEntry.new(key: "shape" , value: Tensorflow::AttrValue.new(shape: Tensorflow::TensorShapeProto.new(dim: [Tensorflow::TensorShapeProto::Dim.new(size: 2)]))))
node {
name: "Placeholder"
op: "Placeholder"
attr {
key: "dtype"
value {
type: DT_FLOAT
}
}
attr {
import tensorflow as tf
a = tf.Graph()
input1 = tf.placeholder(tf.float32, shape=(2))
input2 = tf.placeholder(tf.float32, shape=(2))
output = tf.mul(input1, input2)
with tf.Session() as sess:
print(sess.run([output], feed_dict={input1:[7,2], input2:[2,4]}))
tf.train.write_graph(sess.graph_def, 'models/', 'test_graph_multi_dim.pb', as_text=True)
require 'tensorflow'
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[ [2.0,5.0],
[1.0,-20.0]],
[[124.0,5.0],
[53.0,-2.0]],
[[1.0,0.0],
[0.0,1.0]]
require 'tensorflow'
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[2, 2.3], [ 10, 6.2]])
tensor_2 = Tensorflow::Tensor.new([[4, 3.2], [ 47, 1.2]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
placeholder_2 = graph.placeholder('tensor2', tensor_2.type_num)
opspec = Tensorflow::OpSpec.new('Addition_of_tensors', 'Add', nil, [placeholder_1, placeholder_2])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
import tensorflow as tf
import numpy as np
input1 = tf.placeholder(tf.int64, shape=(2, 2), name = "input1")
input2 = tf.placeholder(tf.int64, shape=(2, 2), name = "input2")
output = tf.add(input1, input2, name = "output")
with tf.Session() as sess:
tf.train.write_graph(sess.graph_def, "model/", "graph.pb", as_text=False)
/////////////////////////////////////////////////////////////////////
// = NMatrix
//
// A linear algebra library for scientific computation in Ruby.
// NMatrix is part of SciRuby.
//
// NMatrix was originally inspired by and derived from NArray, by
// Masahiro Tanaka: http://narray.rubyforge.org
//
// == Copyright Information