Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
I have an "tensorflow.python.framework.ops.Graph" object loaded from a .pb file. def load_pb(path_to_pb): with tf.compat.v1.gfile.GFile(path_to_pb, "rb") as f: graph_def = tf.compat....
#1: Initial revision
How to execute and find gradients of a tensorflow (1) graph object
I have an "tensorflow.python.framework.ops.Graph" object loaded from a .pb file. ``` def load_pb(path_to_pb): with tf.compat.v1.gfile.GFile(path_to_pb, "rb") as f: graph_def = tf.compat.v1.GraphDef() graph_def.ParseFromString(f.read()) with tf.Graph().as_default() as graph: tf.import_graph_def(graph_def, name='') return graph g = load_pb("some_file.pb") ``` I also know that tensorflow models can be executed or have the gradient found through this process ``` x_tensor = tf.convert_to_tensor(inputs2, dtype=tf.float32) with tf.GradientTape() as t: t.watch(x_tensor) output = new_model(x_tensor) gradients = t.gradient(output, x_tensor) score = float(output) ``` However, I am having a hard time getting the former tensorflow graph "g" to accept any input. It cannot be called as a function, or subscripted. I *think* the model takes a vector of arbitrary length as input, but I don't know how to find out. I want to: 1. Be able to input and output data from this graph 2. Be able to find the gradient of the output with respect to the input, if possible.