tf | TensorFlow samples | Machine Learning library
kandi X-RAY | tf Summary
kandi X-RAY | tf Summary
TensorFlow samples
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Load data and labels .
- Pads the contents to the specified number of characters .
- Split word into words .
- Return one - hot vector corresponding to the given index .
- Log content to stdout .
tf Key Features
tf Examples and Code Snippets
Community Discussions
Trending Discussions on tf
QUESTION
ANSWER
Answered 2021-Mar-18 at 15:40You need to define a different surrogate posterior. In Tensorflow's Bayesian linear regression example https://colab.research.google.com/github/tensorflow/probability/blob/master/tensorflow_probability/examples/jupyter_notebooks/Probabilistic_Layers_Regression.ipynb#scrollTo=VwzbWw3_CQ2z
you have the posterior mean field as such
QUESTION
I am trying to use my own train step in with Keras by creating a class that inherits from Model. It seems that the training works correctly but the evaluate function always returns 0 on the loss even if I send to it the train data, which have a big loss value during the training. I can't share my code but was able to reproduce using the example form the Keras api in https://keras.io/guides/customizing_what_happens_in_fit/ I changed the Dense layer to have 2 units instead of one, and made its activation to sigmoid.
The code:
...ANSWER
Answered 2021-Jun-12 at 17:27As you manually use the loss and metrics function in the train_step
(not in the .compile
) for the training set, you should also do the same for the validation set or by defining the test_step
in the custom model in order to get the loss score and metrics score. Add the following function to your custom model.
QUESTION
I have a problem about not accessing GPU in PyCharm and I use NVIDIA as GPU.
I installed tensorflow-gpu
in Python Interpreter of Setting part in Pycharm and then I run the code but I still cannot access it.
I wonder if I should use CUDA library? How can I fix it?
Here is my code snippet which is shown below.
...ANSWER
Answered 2021-Jun-14 at 11:14I fixed my issue.
Here are the steps of solving that issue.
1 ) Download CUDA from https://developer.nvidia.com/cuda-downloads
2 ) Download CUDNN from https://developer.nvidia.com/rdp/cudnn-download
3 ) Copy bin,include and lastly lib from CUDNN zip file and paste it C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA{version}
4 ) Then run the .py
code in PyCharm and it perceives GPU at last.
QUESTION
The Question
How do I best execute memory-intensive pipelines in Apache Beam?
Background
I've written a pipeline that takes the Naemura Bird dataset and converts the images and annotations to TF Records with TF Examples of the required format for the TF object detection API.
I tested the pipeline using DirectRunner with a small subset of images (4 or 5) and it worked fine.
The Problem
When running the pipeline with a bigger data set (day 1 of 3, ~21GB) it crashes after a while with a non-descriptive SIGKILL
.
I do see a memory peak before the crash and assume that the process is killed because of a too high memory load.
I ran the pipeline through strace
. These are the last lines in the trace:
ANSWER
Answered 2021-Jun-15 at 13:51Multiple things could cause this behaviour, because the pipeline runs fine with less Data, analysing what has changed could lead us to a resolution.
Option 1 : clean your input dataThe third line of the logs you provide might indicate that you're processing unclean data in your bigger pipeline mmap(NULL,
could mean that | "Get Content" >> beam.Map(lambda x: x.read_utf8())
is trying to read a null value.
Is there an empty file somewhere ? Are your files utf8 encoded ?
Option 2 : use smaller files as inputI'm guessing using the fileio.ReadMatches()
will try to load into memory the whole file, if your file is bigger than your memory, this could lead to errors. Can you split your data into smaller files ?
If files are too big for your current machine with a DirectRunner
you could try to use an on-demand infrastructure using another runner on the Cloud such as DataflowRunner
QUESTION
I would like to know whether there is a recommended way of measuring execution time in Tensorflow Federated. To be more specific, if one would like to extract the execution time for each client in a certain round, e.g., for each client involved in a FedAvg round, saving the time stamp before the local training starts and the time stamp just before sending back the updates, what is the best (or just correct) strategy to do this? Furthermore, since the clients' code run in parallel, are such a time stamps untruthful (especially considering the hypothesis that different clients may be using differently sized models for local training)?
To be very practical, using tf.timestamp()
at the beginning and at the end of @tf.function
client_update(model, dataset, server_message, client_optimizer)
-- this is probably a simplified signature -- and then subtracting such time stamps is appropriate?
I have the feeling that this is not the right way to do this given that clients run in parallel on the same machine.
Thanks to anyone can help me on that.
...ANSWER
Answered 2021-Jun-15 at 12:01There are multiple potential places to measure execution time, first might be defining very specifically what is the intended measurement.
Measuring the training time of each client as proposed is a great way to get a sense of the variability among clients. This could help identify whether rounds frequently have stragglers. Using
tf.timestamp()
at the beginning and end of theclient_update
function seems reasonable. The question correctly notes that this happens in parallel, summing all of these times would be akin to CPU time.Measuring the time it takes to complete all client training in a round would generally be the maximum of the values above. This might not be true when simulating FL in TFF, as TFF maybe decided to run some number of clients sequentially due to system resources constraints. In practice all of these clients would run in parallel.
Measuring the time it takes to complete a full round (the maximum time it takes to run a client, plus the time it takes for the server to update) could be done by moving the
tf.timestamp
calls to the outer training loop. This would be wrapping the call totrainer.next()
in the snippet on https://www.tensorflow.org/federated. This would be most similar to elapsed real time (wall clock time).
QUESTION
Trying to implement Azure WAF policy and associate with http listener the code was working fine until I try to include a new optional parameter called http_listener_ids
Tf code:
...ANSWER
Answered 2021-Jun-15 at 10:40The documentation for the azurerm_web_application_firewall_policy
resource is out of date but http_listener_ids
and path_based_rule_ids
are read only now (as of v2.55.0) so you can't set them and can only read them as an attribute of the resource.
QUESTION
Say I have an MLP that looks like:
...ANSWER
Answered 2021-Jun-15 at 02:43In your problem you are trying to use Sequential API to create the Model. There are Limitations to Sequential API, you can just create a layer by layer model. It can't handle multiple inputs/outputs. It can't be used for Branching also.
Below is the text from Keras official website: https://keras.io/guides/functional_api/
The functional API makes it easy to manipulate multiple inputs and outputs. This cannot be handled with the Sequential API.
Also this stack link will be useful for you: Keras' Sequential vs Functional API for Multi-Task Learning Neural Network
Now you can create a Model using Functional API or Model Sub Classing.
In case of functional API Your Model will be
Assuming Output_1 is classification with 17 classes Output_2 is calssification with 2 classes and Output_3 is regression
QUESTION
I am trying to use hclwrite to generate .tf files.
According to the example in hclwrite Example, I can generate variables like foo = env.PATH
, but I don't know how to generate more forms of expressions. For example, the following.
ANSWER
Answered 2021-Jun-14 at 19:21The hclwrite
tool currently has no facility to automatically generate arbitrary expressions. Its helper functions are limited only to generating plain references and literal values. SetAttributeValue
is the one for literal values, and so that's why the library correctly escaped the ${
sequence in your string, to ensure that it will be interpreted literally.
If you want to construct a more elaborate expression then you'll need to do so manually by assembling the tokens that form the expression and then calling SetAttributeRaw
instead.
In the case of your example, it looks like you'd need to generate the following eight tokens:
TokenOQuote
with the bytes"
TokenQuotedLit
with the byteshello
TokenTemplateInterp
with the bytes${
TokenIdent
with the bytesvar
TokenDot
with the bytes.
TokenIdent
with the bytesstage
TokenTemplateSeqEnd
with the bytes}
TokenCQuote
with the bytes"
The SetAttributeValue
function is automating the simpler case of generating three tokens: TokenOQuote
, TokenQuotedLit
, TokenCQuote
.
You can potentially automate the creation of tokens for the var.stage
portion of this expression by using TokensForTraversal
, which is what SetAttributeTraversal
does internally. However, unless you already have a parsed hcl.Traversal
representing var.stage
, or unless you need things to be more dynamic than you've shown in practice, I expect that it would take more code to construct that input traversal than to just write out the three tokens literally as I showed above.
QUESTION
I am trying to make a next-word prediction model with LSTM + Mixture Density Network Based on this implementation(https://www.katnoria.com/mdn/).
Input: 300-dimensional word vectors*window size(5) and 21-dimensional array(c) representing topic distribution of the document, used to train hidden initial states.
Output: mixing coefficient*num_gaussians, variance*num_gaussians, mean*num_gaussians*300(vector size)
x.shape, y.shape, c.shape with an experimental 161 obserbations gives me such:
(TensorShape([161, 5, 300]), TensorShape([161, 300]), TensorShape([161, 21]))
...ANSWER
Answered 2021-Jun-14 at 19:07for MDN model , the likelihood for each sample has to be calculated with all the Gaussians pdf , to do that I think you have to reshape your matrices ( y_true and mu) and take advantage of the broadcasting operation by adding 1 as the last dimension . e.g:
QUESTION
I'm trying to compute shap values using DeepExplainer, but I get the following error:
keras is no longer supported, please use tf.keras instead
Even though i'm using tf.keras?
...ANSWER
Answered 2021-Jun-14 at 14:52TL;DR
- Add
tf.compat.v1.disable_v2_behavior()
at the top for TF 2.4+- calculate shap values on numpy array, not on df
Full reproducible example:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install tf
You can use tf like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page