logo
down
shadow

Changing the current graph of tf.placeholder objects in Tensorflow: Is it possible?


Changing the current graph of tf.placeholder objects in Tensorflow: Is it possible?

By : Stacy
Date : October 25 2020, 09:10 AM
will be helpful for those in need If you have 2 graphs, you can copy operations and variables from a graph to the other using the tf.contrib.copy_graph module.
In particular, you can use the copy_op_to_graph to copy the placeholder pl from graph g1 to graph g2:
code :
tf.contrib.copy_graph.copy_op_to_graph(
    pl,
    g2,
    [],
    scope=''
)


Share : facebook icon twitter icon
Tensorflow Placeholder is not an element of this graph

Tensorflow Placeholder is not an element of this graph


By : Jack N
Date : March 29 2020, 07:55 AM
it helps some times I believe you have a plain old Python scope problem here. You define x in the __init__ method but nowhere is the value x passed to anyone.
When you get to
code :
    feed_dict_train = {x: x_batch,
                       y_true: y_true_batch}
Tensorflow graph with multiple inputs wihtout tf.placeholder for validation

Tensorflow graph with multiple inputs wihtout tf.placeholder for validation


By : Francuskuspaiman Uni
Date : March 29 2020, 07:55 AM
this will help The hack-ish way - node replacement
The most trivial way, although definitely not the most beautiful, would just be to use the node created by the tf.data API as an input to the feed_dict - this is because in Tensorflow you can replace the value of any node in the computation graph by feeding it's value directly to the feed_dict.
code :
batch_input = tf_train_data_foo()
validation_input = tf_validation_data_foo()

model = build_model(batch_input)
optimization_step = some_optimization_foo(model)

# Regular train
session.run(optimization_step)

# Validation run
validation_data = session.run(validation_input)
session.run(model, {batch_input: validation_data})
tensorflow pass numpy array to graph using placeholder vs tf.convert_to_tensor()

tensorflow pass numpy array to graph using placeholder vs tf.convert_to_tensor()


By : MiNet
Date : March 29 2020, 07:55 AM
hop of those help? tf_convert_to_tensor is highly unpractical because it does not scale. See the example below:
code :
X = np.random.rand(3,3)
Y = np.random.rand(3,3)
X_tensor = tf.convert_to_tensor(X)
X_squared = tf.square(X_tensor)
Y_tensor = tf.convert_to_tensor(Y)
Y_squared = tf.square(Y)
with tf.Session() as sess:
    x = sess.run(X_squared)
    y = sess.run(Y_squared)
X = np.random.rand(3,3)
Y = np.random.rand(3,3)
graph_input = tf.placeholder(shape=[None, None], dtype=tf.float64)
squared = tf.square(graph_input)
with tf.Session() as sess:
    x = sess.run(squared, feed_dict={graph_input: X})
    y = sess.run(squared, feed_dict={graph_input: Y})
Tensorflow Graph - check if a node depends on a placeholder

Tensorflow Graph - check if a node depends on a placeholder


By : user3191042
Date : March 29 2020, 07:55 AM
it helps some times Checking dependency between tensors in a graph can be done with a function like this:
code :
import tensorflow as tf

# Checks if tensor a depends on tensor b
def tensor_depends(a, b):
    if a.graph is not b.graph:
        return False
    gd = a.graph.as_graph_def()
    gd_sub = tf.graph_util.extract_sub_graph(gd, [a.op.name])
    return b.op.name in {n.name for n in gd_sub.node}
import tensorflow as tf

x = tf.placeholder(name='X', dtype=tf.int64, shape=[])
y = tf.placeholder(name='Y', dtype=tf.int64, shape=[])
p = tf.add(x, y)
q = tf.add(x, x)
print(tensor_depends(q, x))
# True
print(tensor_depends(q, y))
# False
Tensorflow: Replacing/feeding a placeholder of a graph with tf.Variable?

Tensorflow: Replacing/feeding a placeholder of a graph with tf.Variable?


By : peter zhu
Date : March 29 2020, 07:55 AM
I wish this helpful for you I have a model M1 whose data input is a placeholder M1.input and whose weights are trained. My goal is to build a new model M2 which computes the output o of M1 (with its trained weights) from an input w in a form of tf.Variable (instead of feeding actual values to M1.input). In other words, I use the trained model M1 as a black-box function to build a new model o = M1(w) (in my new model, w is to be learned and the weights of M1 are fixed as constants). The problem is that M1 only accepts as its input M1.input through which we need to feed actual values, not a tf.Variable like w. , This is possible. What about:
code :
import tensorflow as tf


def M1(input, reuse=False):
    with tf.variable_scope('model_1', reuse=reuse):
        param = tf.get_variable('param', [1])
        o = input + param
        return o


w = tf.get_variable('some_w', [1])
plhdr = tf.placeholder_with_default(w, [1])

output_m1 = M1(plhdr)

with tf.Session() as sess:

    sess.run(tf.global_variables_initializer())

    sess.run(w.assign([42]))

    print(sess.run(output_m1, {plhdr: [0]}))  # direct from placeholder
    print(sess.run(output_m1))                # direct from variable
Related Posts Related Posts :
  • Cannot install pyqt5 for python3.4 on windows 10
  • Gravity Problems
  • Where to position `import` modules inside an class?
  • Python OpenCV: Cannot resize image
  • Print on the same spot in IPython console
  • Disable logging except in tests
  • Writing json to file in s3 bucket
  • Sorting numpy array created by laspy
  • Open an XML file through URL and save it
  • How to build a 2-level dictionary?
  • error installing scipy using pip on windows 10
  • __str__ from my own matrix, python
  • python re how to Extract fields use findall()?
  • how to read a value from text HI file using python?
  • How to use horizontal scrolling in treeview,here i use tree view to make a table
  • Dependant widgets in tkinter
  • Read and write in a JSON file using python 2.x
  • How to fix the function issue while allowing it to be dynamic?
  • Set long strings as default value in class
  • What is the REGEX for any number with a string(letters and punctuations)?
  • pip with several version of python on windows
  • Submitting login form with scrapy
  • How do i edit the favicon in the Browsable API in Django REST framework?
  • multiprocessing.Pool.map_async doesn't seem to... do anything at all?
  • Python Selenium: Stale Element Reference Exception Error
  • Datetime conversion - How to extract the inferred format?
  • Import YAML variables automatically?
  • How to create a powershell shortcut for my python file
  • Python's 'set' operator doesn't work with numpy.nan
  • Pass object fields and one2many fields on same method - Odoo v8
  • Select columns based on column name and location in Pandas
  • Standardizing timeseries in Pandas using interpolation
  • How many tweets can be collected?
  • how format specifier taking value while tuple list is passed
  • How to print a numpy array with data type?
  • Timeout child thread for python3
  • How can I regroup a dataframe and accumulate a colume's values?
  • Bulk Insert into SQL Server with Python not working
  • Removing last rows of each group based on condition in a pandas dataframe
  • Why the css file can not be found in Django template?
  • targeting center of mass - scipy / numpy
  • Foursquare - get tips from VENUE_ID
  • Unpack a dictionary to format
  • encoding special characters in python2
  • Replacing integers with NaN results in the entire column becoming float dtype
  • Python 3.6 - BeautifulSoup4, parse table AttributeError: ResultSet object has no attribute 'findAll'
  • Convert panda date list to python list of date strings
  • escape response from Scrapy to parse json
  • How to create a same dropdown menu for different labels?
  • Why are some python variables uppercase whereas others are lowercase?
  • Machine Learning, What are the common techniques for feature engineering and presenting the model?
  • Modify value of a Django form field during clean() and validate again
  • Heroku Django app can't start up -- 'No module named site'
  • Getting list of dates (excluding weekends)
  • Im trying to create the regular expression to include the text and not the href
  • Python file.readline(2) reads first 2 charectars
  • Groupby with handling empty bin in python
  • Modifying Gcode
  • calling a value in a dictionary within a dictionary (reading a json file)
  • Bouncing ball invalid syntax why is that?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org