# \#tf\_function

**URL:** https://discuss.ai.google.dev/tag/373-tag/373.md

[Latest](https://discuss.ai.google.dev/latest.md) · [Categories](https://discuss.ai.google.dev/categories.md) · [Tags](https://discuss.ai.google.dev/tags.md)

---

## [How to apply 3D data augmentation to my dataset?](https://discuss.ai.google.dev/t/how-to-apply-3d-data-augmentation-to-my-dataset/27747)

<div class="topic-metadata">

**Author:** [@matca](https://discuss.ai.google.dev/u/matca)\
**Replies:** 2\
**Last updated:** [December 27, 2025, 7:45pm UTC](https://discuss.ai.google.dev/t/how-to-apply-3d-data-augmentation-to-my-dataset/27747 "2025-12-27T19:45:56Z")

</div>

I have the augmentations in functions, this is one example: def random\_rotatation(img\_numpy, min\_angle, max\_angle): all\_axes = \[(1, 0), (1, 2), (0, 2)\] angle = np.random.randint(low=min\_angle, high=max\_angle+1) …

---

## [Tensorflow.js latest version packing and version 1 - Observable Framework](https://discuss.ai.google.dev/t/tensorflow-js-latest-version-packing-and-version-1-observable-framework/92629)

<div class="topic-metadata">

**Author:** [@Juuso\_H](https://discuss.ai.google.dev/u/Juuso_H)\
**Replies:** 2\
**Last updated:** [July 31, 2025, 10:21am UTC](https://discuss.ai.google.dev/t/tensorflow-js-latest-version-packing-and-version-1-observable-framework/92629 "2025-07-31T10:21:34Z")

</div>

Hi, What’s the difference in packing between Tensorflow.js version 1 and the latest version? I try to use Tensorflow.js in Observablehq framework. Version number 1 works fine but latest don’t? It gives error message… T…

---

## [Freezing with jit\_compile=True](https://discuss.ai.google.dev/t/freezing-with-jit-compile-true/18115)

<div class="topic-metadata">

**Author:** [@Jack\_Hunt](https://discuss.ai.google.dev/u/Jack_Hunt)\
**Replies:** 1\
**Last updated:** [November 21, 2024, 8:56am UTC](https://discuss.ai.google.dev/t/freezing-with-jit-compile-true/18115 "2024-11-21T08:56:47Z")

</div>

Hi all, I have been working on a model which makes liberal use of @tf.function(jit\_compile=True). However, when I try to export the model as a Frozen Graph, I am hitting some issues with missing output tensor shapes. How…

---

## [ValueError: Graph disconnected: cannot obtain value for tensor Keras](https://discuss.ai.google.dev/t/valueerror-graph-disconnected-cannot-obtain-value-for-tensor-keras/31767)

<div class="topic-metadata">

**Author:** [@Srishruthi\_Nandigam](https://discuss.ai.google.dev/u/Srishruthi_Nandigam)\
**Replies:** 1\
**Last updated:** [November 20, 2024, 5:16pm UTC](https://discuss.ai.google.dev/t/valueerror-graph-disconnected-cannot-obtain-value-for-tensor-keras/31767 "2024-11-20T17:16:29Z")

</div>

The picture depicts my encoder flow. Also, when i run my decoder, i keep crashing with the same error - ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor(type\_spec=TensorSpec(shape=(None, 409…

---

## [TensorFlow Dataset reduce function too slow after skip](https://discuss.ai.google.dev/t/tensorflow-dataset-reduce-function-too-slow-after-skip/29497)

<div class="topic-metadata">

**Author:** [@Matteo\_Doria](https://discuss.ai.google.dev/u/Matteo_Doria)\
**Replies:** 1\
**Last updated:** [October 29, 2024, 8:59am UTC](https://discuss.ai.google.dev/t/tensorflow-dataset-reduce-function-too-slow-after-skip/29497 "2024-10-29T08:59:40Z")

</div>

Hi everyone, I’m trying to take 100 random elements from cifar10 dataset for each class and reduce them to a single “image” using the mean. The problem is that the reduce function time increases significantly after I u…

---

## [Call a round of training inside tf.vectorized\_map?](https://discuss.ai.google.dev/t/call-a-round-of-training-inside-tf-vectorized-map/30595)

<div class="topic-metadata">

**Author:** [@Lars\_Ericson](https://discuss.ai.google.dev/u/Lars_Ericson)\
**Replies:** 1\
**Last updated:** [October 10, 2024, 5:47am UTC](https://discuss.ai.google.dev/t/call-a-round-of-training-inside-tf-vectorized-map/30595 "2024-10-10T05:47:10Z")

</div>

I have an application which uses tf.linalg.lstsq inside of tf.vectorized\_map to do least-squares regression to fit parameters for a large set of problem instances. Similarly, this Bermudan option algorithm calls trainin…

---

## [tf.autodiff.ForwardAccumulator() in a function decorated with tf.function doesn\`t work for RNNs](https://discuss.ai.google.dev/t/tf-autodiff-forwardaccumulator-in-a-function-decorated-with-tf-function-doesn-t-work-for-rnns/41034)

<div class="topic-metadata">

**Author:** [@Francesco\_Munzone](https://discuss.ai.google.dev/u/Francesco_Munzone)\
**Replies:** 1\
**Last updated:** [October 1, 2024, 10:50am UTC](https://discuss.ai.google.dev/t/tf-autodiff-forwardaccumulator-in-a-function-decorated-with-tf-function-doesn-t-work-for-rnns/41034 "2024-10-01T10:50:08Z")

</div>

I have created a simple model with two SimpleRNN layers to evaluate the JVP. To speed up the calculations I decorated the function with tf.function (as in the test code below). import tensorflow as tf x = tf.random.no…

---

## [Tensorflow: map\_fn and parallel execution](https://discuss.ai.google.dev/t/tensorflow-map-fn-and-parallel-execution/13224)

<div class="topic-metadata">

**Author:** [@Yani\_Boshev](https://discuss.ai.google.dev/u/Yani_Boshev)\
**Replies:** 1\
**Last updated:** [September 26, 2024, 8:44am UTC](https://discuss.ai.google.dev/t/tensorflow-map-fn-and-parallel-execution/13224 "2024-09-26T08:44:42Z")

</div>

According to my expectations map\_fn should execute some function in parallel. Unfortunately, it seems that it executes it sequentially. Here is a brief example I created to verify my concerns. @tf.function def test\_mapf…

---

## [layers.Dense - AttributeError: 'tuple' object has no attribute 'rank' "](https://discuss.ai.google.dev/t/layers-dense-attributeerror-tuple-object-has-no-attribute-rank/32516)

<div class="topic-metadata">

**Author:** [@muhabdullahd](https://discuss.ai.google.dev/u/muhabdullahd)\
**Replies:** 1\
**Last updated:** [June 13, 2024, 8:20am UTC](https://discuss.ai.google.dev/t/layers-dense-attributeerror-tuple-object-has-no-attribute-rank/32516 "2024-06-13T08:20:59Z")

</div>

I am getting the error "AttributeError: ‘tuple’ object has no attribute ‘rank’ " on the line : dense = layers.Dense(4, activation=act\_func)(inputs), in the following function : def gen\_model(act\_func = ‘relu’): input…

---

## [K-Folds and TF.Datasets](https://discuss.ai.google.dev/t/k-folds-and-tf-datasets/32585)

<div class="topic-metadata">

**Author:** [@Andre\_Galhardo](https://discuss.ai.google.dev/u/Andre_Galhardo)\
**Replies:** 1\
**Last updated:** [May 8, 2024, 10:35am UTC](https://discuss.ai.google.dev/t/k-folds-and-tf-datasets/32585 "2024-05-08T10:35:17Z")

</div>

Hello everyone, I’m search for make k-folds or stratified k-folds with Tf.Datasets. It’s possible? I don´t knowledge all tools of TF.Dataset, but use in some basics functions, maybe exist some function with help me to …

---

## [TypeError: '\<' not supported between instances of 'function' and 'function'](https://discuss.ai.google.dev/t/typeerror-not-supported-between-instances-of-function-and-function/31997)

<div class="topic-metadata">

**Author:** [@Aydi\_Walid](https://discuss.ai.google.dev/u/Aydi_Walid)\
**Replies:** 1\
**Last updated:** [January 29, 2024, 3:10pm UTC](https://discuss.ai.google.dev/t/typeerror-not-supported-between-instances-of-function-and-function/31997 "2024-01-29T15:10:57Z")

</div>

good morning, i tried to test the following colab project i correct many errors but i did not find any answer of the following error : model.compile(loss=‘sparse\_categorical\_crossentropy’,optimizer=opt,metrics=\[‘a…

---

## [Error when use L1 loss in U-Net](https://discuss.ai.google.dev/t/error-when-use-l1-loss-in-u-net/26493)

<div class="topic-metadata">

**Author:** [@Duo](https://discuss.ai.google.dev/u/Duo)\
**Replies:** 2\
**Last updated:** [December 22, 2023, 9:41am UTC](https://discuss.ai.google.dev/t/error-when-use-l1-loss-in-u-net/26493 "2023-12-22T09:41:50Z")

</div>

Hi, I’m trying to synthesise MRI image derived from CT using U-Net segmentation. I tried to use L1 as loss function. But when i fit the model, error shows. Please help me on possible reasons. i’m pretty new to deep lear…

---

## [Model predict returning different results compared to tensorflow server running the same model](https://discuss.ai.google.dev/t/model-predict-returning-different-results-compared-to-tensorflow-server-running-the-same-model/26863)

<div class="topic-metadata">

**Author:** [@tensordor](https://discuss.ai.google.dev/u/tensordor)\
**Replies:** 3\
**Last updated:** [December 20, 2023, 1:19pm UTC](https://discuss.ai.google.dev/t/model-predict-returning-different-results-compared-to-tensorflow-server-running-the-same-model/26863 "2023-12-20T13:19:17Z")

</div>

Hi, I’ve been testing and searching high and low, but keep running into this: trained an image classifier on about 1300 images, for 2 classes I use this function to create the training and validation sets: train\_ds =…

---

## [Assign Weights in Loss of Multi-output regression](https://discuss.ai.google.dev/t/assign-weights-in-loss-of-multi-output-regression/32194)

<div class="topic-metadata">

**Author:** [@Manu\_Johny](https://discuss.ai.google.dev/u/Manu_Johny)\
**Replies:** 2\
**Last updated:** [December 6, 2023, 9:05am UTC](https://discuss.ai.google.dev/t/assign-weights-in-loss-of-multi-output-regression/32194 "2023-12-06T09:05:57Z")

</div>

Hello guys, I am working currently on the following problem: I have a regression model that outputs two values f1 and f2. The range of both values are \[0, 1\]. In my training dataset, I have 50 examples with f1 = 0 and 2…

---

## [Problems with training a model on a dataset that doesn't fit into RAM memory](https://discuss.ai.google.dev/t/problems-with-training-a-model-on-a-dataset-that-doesnt-fit-into-ram-memory/32164)

<div class="topic-metadata">

**Author:** [@normalguy19](https://discuss.ai.google.dev/u/normalguy19)\
**Replies:** 3\
**Last updated:** [November 29, 2023, 10:45pm UTC](https://discuss.ai.google.dev/t/problems-with-training-a-model-on-a-dataset-that-doesnt-fit-into-ram-memory/32164 "2023-11-29T22:45:38Z")

</div>

Hi everyone! I’m a student who’s trying to get the python code of a model from a research paper to work. I’ve managed to tweak the code such that it is suitable for my own dataset and such that it can train on a very sm…

---

## [How to configure input as string paramenter with custom component?](https://discuss.ai.google.dev/t/how-to-configure-input-as-string-paramenter-with-custom-component/24061)

<div class="topic-metadata">

**Author:** [@Natielle\_Goncalves](https://discuss.ai.google.dev/u/Natielle_Goncalves)\
**Replies:** 1\
**Last updated:** [November 29, 2023, 2:30am UTC](https://discuss.ai.google.dev/t/how-to-configure-input-as-string-paramenter-with-custom-component/24061 "2023-11-29T02:30:13Z")

</div>

I updated the TFX from 0.22.0 to 1.8.0 and now I’m getting this error: TypeError: Argument input\_params should be a Channel of type \<class 'tfx.types.standard\_artifacts.ExternalArtifact'\> (got test\_string) With 0.22.0 …

---

## [Help! Could not find variable learning\_rate](https://discuss.ai.google.dev/t/help-could-not-find-variable-learning-rate/29404)

<div class="topic-metadata">

**Author:** [@ZWWW](https://discuss.ai.google.dev/u/ZWWW)\
**Replies:** 1\
**Last updated:** [November 23, 2023, 8:18pm UTC](https://discuss.ai.google.dev/t/help-could-not-find-variable-learning-rate/29404 "2023-11-23T20:18:52Z")

</div>

I am currently training something and the code works well with Tensorflow==2.8.0. I want to use some functions in Tensorflow==2.13.1, so I change the env and it raises the following errors: My experimental platform: Ub…

---

## [Loss functions that considers objects and not just tp, fp, fn](https://discuss.ai.google.dev/t/loss-functions-that-considers-objects-and-not-just-tp-fp-fn/29250)

<div class="topic-metadata">

**Author:** [@Gabriel\_Beaudet](https://discuss.ai.google.dev/u/Gabriel_Beaudet)\
**Replies:** 1\
**Last updated:** [November 20, 2023, 10:11am UTC](https://discuss.ai.google.dev/t/loss-functions-that-considers-objects-and-not-just-tp-fp-fn/29250 "2023-11-20T10:11:48Z")

</div>

Hey guys so we have this training system going on at our pace for a while. We have been to ruffer project now and it seams the loss fonctions we use (bce and tversky\_focal\_loss) doesn’t make any difference if the false …

---

## [Problem of learning machine infinity reading images](https://discuss.ai.google.dev/t/problem-of-learning-machine-infinity-reading-images/29251)

<div class="topic-metadata">

**Author:** [@920204q](https://discuss.ai.google.dev/u/920204q)\
**Replies:** 3\
**Last updated:** [November 1, 2023, 12:58am UTC](https://discuss.ai.google.dev/t/problem-of-learning-machine-infinity-reading-images/29251 "2023-11-01T00:58:12Z")

</div>

it’slerrning machine but it will infinity reading images train\_data\_dir = ‘C:\\Users\\92020\\source\\repos\\exercise\\ex.data\\train’ test\_data\_dir = ‘C:\\Users\\92020\\source\\repos\\exercise\\ex.data\\test’ Create an ImageDataGen…

---

## [Determine if in a GradientTape context](https://discuss.ai.google.dev/t/determine-if-in-a-gradienttape-context/30425)

<div class="topic-metadata">

**Author:** [@Jack\_Hunt](https://discuss.ai.google.dev/u/Jack_Hunt)\
**Replies:** 1\
**Last updated:** [September 22, 2023, 8:07pm UTC](https://discuss.ai.google.dev/t/determine-if-in-a-gradienttape-context/30425 "2023-09-22T20:07:45Z")

</div>

Hi all, is there a way to determine from within an op if the op has been invoked under the context of a GradientTape? Something like the following: @tf.function def some\_op(): gt = get\_gradient\_tape\_somehow() …

---

## [Input arguments of tf functions not showing in Spyder](https://discuss.ai.google.dev/t/input-arguments-of-tf-functions-not-showing-in-spyder/29627)

<div class="topic-metadata">

**Author:** [@David\_F](https://discuss.ai.google.dev/u/David_F)\
**Replies:** 1\
**Last updated:** [September 9, 2023, 4:14pm UTC](https://discuss.ai.google.dev/t/input-arguments-of-tf-functions-not-showing-in-spyder/29627 "2023-09-09T16:14:30Z")

</div>

Can anybody tell me why does Spyder/Keras does not show the arguments to TF functions? (the places I marked with red arrows and question marks). The user-defined function model.predict in the console does show the argume…

---

## [tf.keras.optimizers.Adam.apply\_gradients triggers tf.function retracing](https://discuss.ai.google.dev/t/tf-keras-optimizers-adam-apply-gradients-triggers-tf-function-retracing/31489)

<div class="topic-metadata">

**Author:** [@Bryan\_Carty](https://discuss.ai.google.dev/u/Bryan_Carty)\
**Replies:** 1\
**Last updated:** [September 7, 2023, 9:11am UTC](https://discuss.ai.google.dev/t/tf-keras-optimizers-adam-apply-gradients-triggers-tf-function-retracing/31489 "2023-09-07T09:11:11Z")

</div>

I’m getting a memory leak and I believe it to be linked to the following warning: WARNING:tensorflow:6 out of the last 6 calls to \<function \_BaseOptimizer.\_update\_step\_xla at 0x7fa9f8074c20\> triggered tf.function retrac…

---

## [Get 'UnreadVariable' while running the model](https://discuss.ai.google.dev/t/get-unreadvariable-while-running-the-model/31038)

<div class="topic-metadata">

**Author:** [@acraev](https://discuss.ai.google.dev/u/acraev)\
**Replies:** 1\
**Last updated:** [May 3, 2023, 6:30pm UTC](https://discuss.ai.google.dev/t/get-unreadvariable-while-running-the-model/31038 "2023-05-03T18:30:21Z")

</div>

I am running a subclassed model and update parameters using tf.GradientTape(). While the model runs, I continue getting the following message every few seconds. \<tf.Variable 'UnreadVariable' shape=() dtype=int64, numpy=…

---

## [Tensorflow (2.9.1) : Changing the 'trainable' attribute on a layer during training](https://discuss.ai.google.dev/t/tensorflow-2-9-1-changing-the-trainable-attribute-on-a-layer-during-training/30527)

<div class="topic-metadata">

**Author:** [@ankit1089.sony](https://discuss.ai.google.dev/u/ankit1089.sony)\
**Replies:** 3\
**Last updated:** [June 14, 2022, 3:54am UTC](https://discuss.ai.google.dev/t/tensorflow-2-9-1-changing-the-trainable-attribute-on-a-layer-during-training/30527 "2022-06-14T03:54:39Z")

</div>

Consider the following model: class MyModel(keras.Model): def \_\_init\_\_(self, \*\*kwargs): super(MyModel, self).\_\_init\_\_(\*\*kwargs) self.square\_layer = keras.layers.Dense(2) self.cube\_la…

---

## [Accessing an object's attribute in tf.function](https://discuss.ai.google.dev/t/accessing-an-objects-attribute-in-tf-function/30562)

<div class="topic-metadata">

**Author:** [@Passive\_Aggressive](https://discuss.ai.google.dev/u/Passive_Aggressive)\
**Replies:** 13\
**Last updated:** [May 12, 2022, 2:24pm UTC](https://discuss.ai.google.dev/t/accessing-an-objects-attribute-in-tf-function/30562 "2022-05-12T14:24:21Z")

</div>

Hi, I’m trying to manipulate a tensor as an object’s attribute, I’m only using tf.function’s return value here. All assignments are outside the function, I don’t think I’m violating any rules here. But the result is clea…

---

## [Where to apply tf.function](https://discuss.ai.google.dev/t/where-to-apply-tf-function/28266)

<div class="topic-metadata">

**Author:** [@bennofs](https://discuss.ai.google.dev/u/bennofs)\
**Replies:** 1\
**Last updated:** [June 1, 2021, 12:11pm UTC](https://discuss.ai.google.dev/t/where-to-apply-tf-function/28266 "2021-06-01T12:11:01Z")

</div>

At what granularity should I apply tf.function to my models and layers? Should I decorate every layer’s call with @tf.function or just the model layer’s call method, or just the training step? It seems to me that decora…
