Skip to content

Instantly share code, notes, and snippets.

@arafatkatze
Last active September 12, 2016 20:11
Show Gist options
  • Save arafatkatze/9f5fc0bf1918541ad9a1fef4845acf35 to your computer and use it in GitHub Desktop.
Save arafatkatze/9f5fc0bf1918541ad9a1fef4845acf35 to your computer and use it in GitHub Desktop.
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)]))))
graph_def.node.push(node_b)
mat_mul = Tensorflow::NodeDef.new(name: "Mul", op: "Mul", input: ["Placeholder", "Placeholder_1"], attr: [])
mat_mul.attr.push(Tensorflow::NodeDef::AttrEntry.new(key: "T", value: Tensorflow::AttrValue.new(type: 1)))
graph_def.node.push(mat_mul)
encoder = graph_def.serialize_to_string
File.open('graph.pb', 'w') {|file| file.write(encoder)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment