Question:
Hello! First time actually posting on these forums, I believe. I tend to follow the general advice that you should Google for answers first. At this point, I think this one is specific enough (to my case) to warrant a unique post. I’ll show you the full warning first, then my observations/hypothesis as to what’s going on, then the details of my actual hardware and OS.
I’m getting the following warnings:

2021-07-28 15:45:36.855763: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-28 15:45:36.856682: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1871] Adding visible gpu devices: 0
2021-07-28 15:45:36.899944: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudart.so.11.0
2021-07-28 15:45:41.158493: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1258] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-07-28 15:45:41.158534: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1264] 0
2021-07-28 15:45:41.158545: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1277] 0: N
2021-07-28 15:45:41.158768: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-28 15:45:41.159384: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-28 15:45:41.159956: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-28 15:45:41.160578: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1418] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6702 MB memory) → physical GPU (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1)
2021-07-28 15:45:41.205455: W tensorflow/core/framework/cpu_allocator_impl.cc:80] Allocation of 376320000 exceeds 10% of free system memory.
2021-07-28 15:45:41.475303: W tensorflow/core/framework/cpu_allocator_impl.cc:80] Allocation of 376320000 exceeds 10% of free system memory
2021-07-28 15:45:36.838849: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudnn.so.8
2021-07-28 15:45:36.839143: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-28 15:45:36.840230: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-28 15:45:36.850568: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1871] Adding visible gpu devices: 0
2021-07-28 15:45:36.852247: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-07-28 15:45:36.852921: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-28 15:45:36.853943: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1733] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce GTX 1070 computeCapability: 6.1
coreClock: 1.683GHz coreCount: 15 deviceMemorySize: 7.93GiB deviceMemoryBandwidth: 238.66GiB/s
2021-07-28 15:45:36.854084: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-28 15:45:36.855763: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-28 15:45:36.856682: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1871] Adding visible gpu devices: 0
2021-07-28 15:45:36.899944: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudart.so.11.0
2021-07-28 15:45:41.158493: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1258] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-07-28 15:45:41.158534: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1264] 0
2021-07-28 15:45:41.158545: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1277] 0: N
2021-07-28 15:45:41.158768: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-28 15:45:41.159384: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-28 15:45:41.159956: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-28 15:45:41.160578: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1418] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6702 MB memory) → physical GPU (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1)
2021-07-28 15:45:41.205455: W tensorflow/core/framework/cpu_allocator_impl.cc:80] Allocation of 376320000 exceeds 10% of free system memory.
2021-07-28 15:45:41.475303: W tensorflow/core/framework/cpu_allocator_impl.cc:80] Allocation of 376320000 exceeds 10% of free system memory

Observations and Hypothesis
When I first hit the training loop, I’m pretty sure that it begins fine, runs, compiles, and everything. Since I have a mechanical hard drive, I can hear the head moving inside. I started it at around 4:30 PM yesterday, and let it run whilst I was asleep. When I checked it just before going to sleep, the desktop GUI (I think it’s Gnome) had crashed, but the hard drive was still making noise.
At 7AM, when I woke up, I could no longer hear the hard drive going. However, Jupyter Notebook still showed an asterisk, which is meant to indicate that the cell in question (which contained the training loop), was still running.
All of this makes me think that TF was overcommitting - as is the default behavior on Linux (?), and that for some reason, the OOM killer chose to keep TF running instead of GNOME. But given that I didn’t hear the hard drive going, I don’t think the training loop was still going. That would mean that TF crashed too. (?)
Those aforementioned warning messages are what leads me to think that overcommitting could be a factor here. I’m thinking about getting more RAM. Unfortunately my current motherboard only supports DDR3.
OS and specs
OS: Ubuntu 20.04.2 LTS
Kernel: 5.4.0-80-generic
CPU: AMD A10-6800K APU (4) @ 4.1GHz
GPU: GeForce GTX 1070
RAM: 8 GiB DDR3
Thank you for reading this far! Hope I can get some advice.

Context:
Update with more information - since posting the above, I’ve installed more ram (now 16 GB). I’ve also run free -m and nvidia-smi, and I can see that significant amounts of memory are being used by TF - both in the GPU and RAM.
I’m not sure why it’s using such memory. I’m using the following command to help ensure that it at least doesn’t allocate all the memory at once:

gpus = tf.config.experimental.list_physical_devices(‘GPU’)
print(gpus)
tf.config.experimental.set_memory_growth(gpus[0], True)

Do the NUMA errors on my original post have any bearing on TF’s ability to use memory efficiently?

erick@erickusb:~$ free -m
total    	used    	free  	shared  buff/cache   available
Mem:      	16033   	14287     	177      	41    	1568    	1418
Swap:      	7381     	898    	6483
erick@erickusb:~$ nvidia-smi
Sat Jul 31 14:13:48 2021
±----------------------------------------------------------------------------+
| NVIDIA-SMI 460.91.03	Driver Version: 460.91.03	CUDA Version: 11.2 	|
|-------------------------------±---------------------±---------------------+
| GPU  Name    	Persistence-M| Bus-Id    	Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|     	Memory-Usage | GPU-Util  Compute M. |
|                           	|                  	|           	MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 1070	Off  | 00000000:01:00.0  On |              	N/A |
| 36%   53C	P2	34W / 151W |   5056MiB /  8116MiB |  	5%  	Default |
|                           	|                  	|              	N/A |
±------------------------------±---------------------±---------------------+
±----------------------------------------------------------------------------+
| Processes:                                                              	|
|  GPU   GI   CI    	PID   Type   Process name              	GPU Memory |
|    	ID   ID                                               	Usage  	|
|=============================================================================|
|	0   N/A  N/A  	1139  	G   /usr/lib/xorg/Xorg            	101MiB |
|	0   N/A  N/A 	12157  	G   /usr/lib/xorg/Xorg            	187MiB |
|	0   N/A  N/A 	12274  	G   /usr/bin/gnome-shell           	74MiB |
|	0   N/A  N/A 	13778  	G   /usr/lib/firefox/firefox      	113MiB |
|	0   N/A  N/A 	17034  	C   /usr/bin/python3             	4541MiB |
|	0   N/A  N/A 	18032  	G   …mviewer/tv_bin/TeamViewer   	16MiB |
±----------------------------------------------------------------------------+

A couple of additional details… the TF kernel is now crashing instead of the GUI. Also, what I’m trying to implement is more or less Wang’s algorithm 2 in this paper: https://arxiv.org/pdf/1809.03428.pdf 5
I’ve also been playing around with batch size and it doesn’t seem to help much.


Questions about serving tensorflow saved model locally

Question:
Hi. I’m new to learn TensorFlow and DL. I’m working on a application that running on Windows, doing OCR locally.
I’ve learnt something about how to train and test model, but little about deployment the model for production. By now, I just load the trained model and use model.predict(). And then use the PyInstaller to build my codes to a exe package.
The question is, the package is a bit too large. The tensorflow library takes up a lot of space.

image1421×770 271 KB

I wonder if there is any ways to make it smaller? Should I learn something about TensorFlow Extended or tflite so that they will solve my problem?
Thanks in advanced if anyone could help.

Context: I am using tf.keras to build the model.


No poses returned in barebones BlazePose!?

Question:
Hey all! I’m Samperson, you can see some stuff I do on Twitter 1.
I’m having a problem setting up simple BlazePose detection to mess around!
No errors, it appears to function, it just gives me an empty list for poses every call - even when I can tab over to the live demo using the same camera, on the same model, and it works great!
I can’t identify where I’m going wrong, no matter how much example code + documentation I pull from. Here’s the source- could I get another pair of eyes on it? My entire implementation is <50loc, barebones as hell.
I’ve uploaded it all here! 4.
Thank you so much!
-Sam

- a couple uneducated theories -
Maybe my setup can’t read anything off the video element?
I’m also getting sourcemap errors in the console, I’m wondering if I messed up my HTML script tags?

Context:
Hi Samperson,
I don’t have a good answer for you but did you try doing this with MoveNet instead of BlazePose?


Model output not looking as expected (tfjs/tflite) styletransfer model

Question:
Hey all, I’m trying to implement the style transfer from the TFHub: TensorFlow Hub 2 using tf.js but I’m running into a little bit of an issue. I think I’ve got it all hooked up together but the resulting image is not looking very good. Any help would be truly appreciated!
Current result in the browser

652×1042 924 KB

Code
import '@tensorflow/tfjs-backend-cpu';
import{ browser, image, tidy, Tensor, reshape} from '@tensorflow/tfjs-core';
import * as tflite from '@tensorflow/tfjs-tflite'

const predictionUrl = 'https://tfhub.dev/google/lite-model/magenta/arbitrary-image-stylization-v1-256/fp16/prediction/1';
const transferUrl = 'https://tfhub.dev/google/lite-model/magenta/arbitrary-image-stylization-v1-256/fp16/transfer/1';

export async function run() {
  const predictionModel = await tflite.loadTFLiteModel(predictionUrl);
  const transferMode = await tflite.loadTFLiteModel(transferUrl);
  const styleImg = await browser.fromPixelsAsync(document.querySelector('.styleImage'));
  const img = await browser.fromPixelsAsync(document.querySelector('.originalImage'));
  const resizedStyleImage = reshape(image.resizeBilinear(styleImg, [256, 256]), [1, 256, 256, 3]);
  const styleBottleNeck = await tidy(() => predictionModel.predict([resizedStyleImage])) as Tensor;
  const resizedImageTensor =  reshape(image.resizeBilinear(img, [384, 384], true), [1, 384, 384, 3]);
  const output = await tidy(() => transferMode.predict([resizedImageTensor, styleBottleNeck])) as Tensor;
  return browser.toPixels(reshape(image.resizeBilinear(output, [540, 960], true),  [540, 960, 3]), document.querySelector('.canvas'))
}

Context: Hi, can you provide the result from TF using their colab?


Certain softmax shapes won’t convert to tensorflow lite

Question:
Quick question. Why is it that certain softmax shapes will not convert to tensorflow lite? For example (10,26,26) will work but (10,26,26,1) will not. I am getting the following error
Some ops are not supported by the native TFLite runtime, you can enable TF kernels fallback using TF Select. See instructions: https://www.tensorflow.org/lite/guide/ops_select
TF Select ops: Softmax
Details:
	tf.Softmax(tensor<?x10x26x26x1xf32>) -> (tensor<?x10x26x26x1xf32>) : {device = ""}

I am trying to figure out how to solve this while keeping the tf runtime.
I also have a stack overflow topic 1

Context:
Have you checked if is it still related to:

      github.com/tensorflow/tensorflow

      Softmax activations don't get converted to Softmax TFLite operator if ndim > 2 7

        opened

        Dec 18, 2019

          closed

        Mar 6, 2021

          ghop02

        type:bug
        comp:lite
        TF 2.1

    **System information**
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04…): MacOS 10.15.1
- TensorFlow installed from (source or binary): binary
- TensorFlow version (or github SHA if from source): tf-nightly==2.1.0.dev20191203

**Command used to run the converter or code if you’re using the Python API**

```
import pathlib

inpt = tf.keras.layers.Input(shape=[256, 256, 3])
out = tf.keras.layers.Lambda(lambda x: tf.keras.activations.softmax(x))(inpt)
out = tf.keras.layers.Lambda(lambda x: tf.nn.softmax(x))(out)
model = tf.keras.Model(inpt, out)

converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
pathlib.Path('out.tflite').write_bytes(tflite_model)
```

**Failure details**
![image](https://user-images.githubusercontent.com/1422280/71025023-3904e880-20d4-11ea-95fb-29cfea49a44d.png)
This graph shows the difference between the different softmax methods.  When using `tf.keras.activations.softmax`, there is [code](https://github.com/tensorflow/tensorflow/blob/v2.1.0-rc1/tensorflow/python/keras/activations.py#L43-L79) with a workaround for multiple dimensions.  It looks like this was written before the tensorflow op had multi-dimension support.


Question:
Hello Community,
I have a TI tm4c123gh6pm microcontroller and would like to use tensorflow lite on my humble board. However I noticed in the supported section of the tensorflow website that only certain platforms are supported: TensorFlow Lite for Microcontrollers 2 . How would I go about getting Tensorflow lite on my board? Thank you!

Context:
Welcome to the forum.
You can start to check:

      github.com

    tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/docs/new_platform_support.md 6

    <!--
Semi-automated TOC generation with instructions from
https://github.com/ekalinin/github-markdown-toc#auto-insert-and-update-toc
-->

<!--ts-->
   * [Porting to a new platform](#porting-to-a-new-platform)
      * [Step 1: Build TFLM Static Library with Reference Kernels](#step-1-build-tflm-static-library-with-reference-kernels)
      * [Step 2: Customize Logging and Timing Function for your Platform](#step-2-customize-logging-and-timing-function-for-your-platform)
      * [Step 3: Running the hello_world Example](#step-3-running-the-hello_world-example)
      * [Step 4: Building and Customizing Additional Examples](#step-4-building-and-customizing-additional-examples)
      * [Step 5: Integrating Optimized Kernel Implementations](#step-5-integrating-optimized-kernel-implementations)
   * [Advanced Integration Topics](#advanced-integration-topics)
   * [Getting Help](#getting-help)

<!-- Added by: advaitjain, at: Thu 12 Aug 2021 04:48:03 PM PDT -->

<!--te-->

# Porting to a new platform

  This file has been truncated. show original


How can i solve overfitting problem in this model?

Question:
I think I have an overfitting problem … my goal is image captioning Datasets : training 8000 … testing 1000 this my model for 50 epochs
def define_model(vocab_size, max_length):
inputs1 = Input(shape=(1120,))
f1 = Dropout(0.5)(inputs1)
f2 = Dense(256, activation='relu')(f1)
inputs2 = Input(shape=(max_length,))
s1 = Embedding(vocab_size, 256, mask_zero=True)(inputs2)
s4 = GRU(512)(s1)
decoder1 = Concatenate()([f2, s4])
f3 = Dropout(0.5)(decoder1)
decoder2 = Dense(256, activation='relu')(f3)
outputs = Dense(vocab_size, activation='softmax')(decoder2)
model = Model(inputs=[inputs1, inputs2], outputs=outputs)
opt =tf.keras.optimizers.Adam(lr=4e-4)
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
return model

I tried also to use BatchNormalization and learning rate with 0.0001 but the performance become poor

Context:
Hi Sam,
I don’t have an answer to your question, sorry but I have one suggestions:

there’s this tutorial: Image captioning with visual attention  |  TensorFlow Core 5 that might give you some ideas.

good luck


Question:
Hi all
I am using concatenate in one of model which im using as pretrained model and then im adding few more layers which behaves like resnet connection and im using Concatenate instead of add since my earlier model also has Concatenate and new model also has Concatenate
i get this error ValueError: The name "concatenate" is used 2 times in the model. All layer names should be unique.
i tried naming concatenate using looping through layer.name but i couldn’t rename it so i tried adding
X = Concatenate(axis=-1,name="hello")([X1,X2,X3])
but i get similar error

Context:
Hi,
Can you post a code snippet of what you are doing? maybe a colab?


Gradient normal clipping having an unusually strong effect despite no clear evidence of exploding gradients

Question:
Hi,
I’m trying to implement FasterRCNN in Keras and having enormous difficulty doing so. I believe I am encountering some sort of numerical stability issue. When I try to train only the region proposal network (VGG16 + a couple convolution layers tacked on producing two output maps) on a small subset of images, training progress as measured by recall % is very slow and oscillates quite a bit.
As I enable clipnorm, with values like 8, 4, and 1, behavior improves. I don’t see losses exploding or turning into NaNs in any case and am at a loss as to how to debug the issue.
I suspect the issue must involve my loss functions but they are relatively simple (apart from a lot of reshaping of tensors). What would be a good way to debug this?
I’ve thought of printing out the gradient norm per training sample but am not sure how to obtain the gradient in the first place. Most of the examples I’ve seen online no longer work with TF 2.0.
Thank you,
Bart

Context: Have you already tried to finetune our reference implementation 1 on your data?


What will i miss if i didn’t user tensorflow lite model?

Question: I am developing a ML android app, i know i can use Keras and then turn it to a custom tensorflow model, but i don’t want to depend on an API, so what will i miss if i just train my model with Python and then use the weights i get in my application?

Context:
But with the weights, how are you going to run this model on your app? You’ll need more then the weights but also the operations your model needs.
Do you have any specific reason for not wanting to use the dependency?
TFLite takes care of everything regarding loading the model and executing inference using GPU or other accelerators when available.


Question:
Is there any chance that we can use the mixed precision on google colab?

image1096×57 11.3 KB

Context: If the Colab allocate a T4 GPU yes or you can try on the TPU runtime


W tensorflow/core/framework/op_kernel.cc:1767] op_requires failed at ctc_loss_op.cc:213 : invalid argument: labels length is zero in batch 3

Question:
w tensorflow/core/framework/op_kernel.cc:1767] op_requires failed at ctc_loss_op.cc:213 : invalid argument: labels length is zero in batch 3
Anyboy help me to resolve above issue.

Context: Can you share your code?


Question: Is there any way to create backward computational graph with gradients either in tensorflow/keras?

Context: Can you explain a little bit more your use case?


Question:
I am currently working on an object detection application for Android (written in Java) that uses Google ML and TensorFlow Lite. The application essentially focuses on drawing a boundingBox around detected objects within a live streamed preview, provided by my device camera (via CameraX). To construct the base of this application, I used CameraX to build my camera view, and then Google ML to build the framework. The custom TF Lite model I use as a library can be found here 2.
Now onto the problem, HERE 5 is what my object detection application looks like when it detects an object. As you can see, there is a heavy amount of misalignment with the boundingBox, making it appear “off”.  Excuse the fact that it’s labelled as a letter opener, but this problem is persistent with any object, at any angle on the screen. It appears to be off by the same metric, always appearing just slightly above any object. My biggest concern lies with how this issue can be resolved, whether the problem is because of the TFLite model or something unrelated. The boundingBox seems to be missing its detected object by a noticeable amount.
The following DrawGraphic.java class is what’s responsible for drawing the boundingbox, so here it is:

@SuppressLint(“ViewConstructor”)
public class DrawGraphic extends View {
Paint borderPaint, textPaint;
Rect rect;
String text;

public DrawGraphic(Context context, Rect rect, String text) {
    super(context);
    this.rect = rect;
    this.text = text;

    borderPaint = new Paint();
    borderPaint.setColor(Color.WHITE);
    borderPaint.setStrokeWidth(10f);
    borderPaint.setStyle(Paint.Style.STROKE);

    textPaint = new Paint();
    textPaint.setColor(Color.WHITE);
    textPaint.setStrokeWidth(50f);
    textPaint.setTextSize(32f);
    textPaint.setStyle(Paint.Style.FILL);
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawText(text, rect.centerX(), rect.centerY(), textPaint);
    canvas.drawRect(rect.left, rect.bottom, rect.right, rect.top, borderPaint);
}

}

Any additional information needed to supplement this question shall be provided upon request.

Context: To avoid cramming this post, here 5 is a link to my Pastebin that has all my MainActivity.java code in it, including the code needed to call this class.


Question: I was thinking that maybe the sigmoid operation could be sped up using a CUDA intrinsic, __expf. Before I try to write a custom operation, is tensorflow already doing this? I’ve spent several hours looking through the sourcecode, but because of how the functor declarations are separated from the implementation, I’ve been having trouble figuring this one.

Context:
Hi, I think you can follow the same path for the cu files as in:

      stackoverflow.com

  tf.nn.sigmoid implementation in TensorFlow 2

  tensorflow, tensorflow2.0

  asked by

    George

  on 09:02PM - 30 Oct 19 UTC


Difference between “train_on_batch()” and “test_on_batch()” return values

Question:
Hi.
I’m using Keras.
version:
Python 3.6.2
keras                   2.6.0
tensorflow              2.6.0
There is a difference between train_on_batch() and test_on_batch() loss.
What is the reason for this?
train_on_batch(), test_on_batch(), evaluate()
--------------------------------------------------------------
:
0.5317689776420593, 0.5236611366271973, 0.5236611366271973
0.5239976644515991, 0.519664466381073, 0.519664466381073
0.5211538076400757, 0.515764057636261, 0.515764057636261
0.5445187091827393, 0.5118800401687622, 0.5118800401687622
0.5287842750549316, 0.5079948902130127, 0.5079948902130127
0.49349671602249146, 0.5042303800582886, 0.5042303800582886
:

The loss of test_on_batch () and evaluate () was the same.
The difference between the values of train_on_batch () and test_on_batch () can be extremely large, confusing which is the correct value.

Context:
Take a look at:

      stackoverflow.com

  Different loss values computed by train_on_batch and evaluate 26

  tensorflow, machine-learning, keras

  asked by

    Jakub Biały

  on 01:17PM - 26 Jan 21 UTC


Question:
I use ONNX to convert Pytorch to tflite and use flutter with package ‘tflite_flutter: ^0.9.0’ to deploy model. But the tflite model run on Colab output differently from flutter (Colab is the correct one). On Colab, image must be transpose to [1,3,256,256] to be feed on the model. But I don’t know how to transpose Image shape on Flutter and feed the image with model shape [1,3,256,256].
After I run ‘interpreter.run(tensorImage.buffer, probabilityBuffer.buffer)’, The output is different from the output from Colab. Output shape from flutter is 1D array which length is [196608].
How to feed image to model shape [1,3,256,256] on flutter.

Context:
Have you tried with

      github.com/onnx/onnx-tensorflow

      ONNX->"TensorFlow Lite micro" fundamentally broken because of transpose operations 4

        opened

        Feb 12, 2021

          maartenvds

    **Problem**

In my usecase, I need to port a model (only containing conv, relu… and maxpool layers) from PyTorch to TensorFlow Lite micro, using the following conversions: PyTorch->ONNX->TensorFLow->Tensorflow Lite micro. The microcontroller kernels of TFLite however only support NHWC format and there is no support for a transpose layer (see supported layers [here](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/all_ops_resolver.cc)). In CPU mode, onnx-tf inserts transpose operations before and after every conv layer so the conv layers can work with NHWC format. However, the rest of the network is kept in NCHW format. What I need is a network with only NHWC tensors for all layers without any transpose operations (also input/output layers should have NHWC format).

It would be nice if onnx-tf had a mode where you can completely convert a model that is only using NCHW format to a model that is only using NHWC format instead of creating hybrids as is done by the current implementation.
I know this is currently not supported and there is probably not an easy solution for this. But is want to indicate that a conversion from ONNX->TFLite micro is currently fundamentally broken for any given model because of the transpose ops.

We could also fix the problem at the TFLite micro side, by implementing a transpose op, but that is a more wasteful solution given the unnecessary overhead of transpose operations on an already very constrained platform. Fixing the issue in TensorFlow by rewriting the graph seems a bit too complex to do and error prone to future changes.

I therefore kindly ask to consider implementing an additional mode in the converter if possible. I'm willing to contribute if necessary.

**Python, ONNX, ONNX-TF, Tensorflow version**

 - Python version: 3.6.5
 - ONNX version: 1.8.0
 - ONNX-TF version: 1.7.0 (master branch, commit: db092105ceebe076610a1b27c1fc1553978c17cd)
 - Tensorflow version: 2.3.1


Question: hy, I have tflite mode which dimension is  [1,3,224,224] i wanted to convert this into dimension [1,224,224,3] can one can provide me a code to do this

Context:
hi,
if your plan is to perform inference with your tflite model, you can convert the inputs to the input shape specification of your model, you can simply reshape the image to [1, 3, 224, 224] .
otherwise check this tf.lite.Interpreter  |  TensorFlow Core v2.5.0 21


TFlite model maker object_detector.create hang

Question:
Firstly, some details on my software/ hardware:
TF 2.5.0
TF model maker 0.3.2
GPU RX3080 16GB
32GB of DRAM
Ubuntu 18.04 LTS
Nvidia Driver Version: 471.68       CUDA Version: 11.4
I have been trying to train a custom model using “efficientdet_lite1” spec but somehow it always hang randomly mid way in
model = object_detector.create() call
and not always in the same epoch runs:
e.g.
109/176 [=================>…] - ETA: 46s - det_loss: 0.4381 - cls_loss: 0.2731…
I tried to debug by adding
tf.get_logger().setLevel(‘DEBUG’)
but nothing is printed when the hang happens.
Any hint welcome?
I have also tried TF 2.6.0, nightly-builds, etc

Context:
I think I may have found a fix.
After reading
https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars 2
I tried setting
CUDA_LAUNCH_BLOCKING =1
And I completed my training without any issue! Hope I can help anyone having the same issue.


Question:
TFMA end-to-end example link is broken TFMA explanation page.
end-to-end example on GitHub 2.
How it can be fixed ?
link to page : Introducing TensorFlow Model Analysis: Scaleable, Sliced, and Full-Pass Metrics — The TensorFlow Blog 5

Context:
I think It Is moved to

      github.com

tfx/tfx/examples/chicago_taxi_pipeline at master · tensorflow/tfx 4

  master/tfx/examples/chicago_taxi_pipeline

  TFX is an end-to-end platform for deploying production ML pipelines


Multi-Person Pose Estimation in TensorFlow lite

Question:
I plan to use TensorFlow lite pose estimation on Android.
I inquire if Multi-Person Pose Estimation is possible instead of Single-Person Pose Estimation.
In TensorFlow.js, I can choose between Single-Person Pose Estimation and Multi-Person Pose Estimation.
Multi-Person Pose Estimation related functions and APIs cannot be found in TensorFlow lite.
I would appreciate it if you could tell me how to use the Multi-Person Pose Estimation function and API in TensorFlow lite.

Context:
Hi @hssplus ,
Can you provide a link for TensorFlow.js where there is multi person pose estimation?


Tensorflow running slower after cuda installation

Question:
Hello everyone,
Recently I’ve been struggling to install tensorflow with cuda and being able to run locally. Finally, I’ve managed to install it on windows, but the strange thing is that now running algorithm in the gpu is slower than running it in the cpu prior to cuda installation. When I’m running it now the gpu is two times faster than the cpu, but before the cuda installation, the cpu was running faster.
I’m using tensorflow 2.5.0. My computer is the gigabyte aero 15 kb with a rtx 2060. And cuda toolkit version 11.4.
Any suggestions?
Thank you.

Context:
Can you check if the GPU is visibile?

      TensorFlow

tf.config.list_physical_devices  |  TensorFlow Core v2.6.0 9

  Return a list of physical devices visible to the host runtime.

      TensorFlow

tf.config.list_logical_devices  |  TensorFlow Core v2.6.0 4

  Return a list of logical devices created by runtime.


Question:
I am trying to make an android based app with tflite model.
With tflite_model_maker, the image_classifier does not seem to have any compilation functionality.
I want to add tfa metrics, monitoring metrics, early stopping, etc in my model.
Is there any way to do so or maybe we could use our saved model(H5 ) and load it .
I have tried using tf.lite.TFLiteConverter.from_keras_model(model).But there at a point I faced issues of tensorBuffer in tflite model.

Context:
The output of Model Maker can be a regular saved_model file and with that you can load and calculate additional metrics but I don’t think you can use early stoping
To use the TFLite model, I’d suggest you look into Task Library, it makes everything MUCH easier: TensorFlow Lite Task Library 5


Tensorflow Developer Certificate on DataSpell

Question:
Jetbrains is releasing a new IDE that is focused on Data Science called DataSpell 2 and it seems more comfortable to use than PyCharm because you can edit the cell on the preview rather than a separate source code kind of editor.
Will it be possible to take the Tensorflow Developer 3 exam on DataSpell? I’m planning to take the exam in a couple of months during my free time.
Thanks in advance,

Context: @Jocelyn_Becker or @Laurence_Moroney might be able to answer this


What is a good IDE to read TensorFlow Source Code and contribute code for it?

Question:
The Codebase of Tensorflow covers many different languages, mainly Python and C++, but many IDE is specific to one language. I have tried to use Clion to read TensorFlow code, but it seems that Clion does not deal good with bazel: It does not seem to resolve methods imported from other files, so I can not navigate though the code easily. Here is an example discussing this problem 4.
What IDE do the developers of TensorFlow use to write code for it?

Context:
Have you tried to use the official VSCode devcontainer:

      github.com

vscode-dev-containers/repository-containers/github.com/tensorflow/tensorflow/.de... 28

  main/repository-containers/github.com/tensorflow/tensorflow/.devcontainer

  A repository of development container definitions for the VS Code Remote - Containers extension and GitHub Codespaces - vscode-dev-containers/repository-containers/github.com/tensorflow/tensorflow/...


How to write numpy array to checkpoint in PyTorch

Question:
To write checkpoint in TensorFlow, first it will build the computational graph, the nodes and operations and how they are connected to each other and then it will use session.
Following codes storing the checkpoint in TensorFlow:
import os
import tensorflow.compat.v1 as tf
import numpy as np

def savecheckpoint(var_name, db, dtype, ckpt_path):
  with tf.Graph().as_default():
    init_value = tf.py_func(lambda: db, [], dtype, stateful=False)
    init_value.set_shape(db.shape)
    tf_db = tf.get_variable(var_name, initializer=init_value)
    saver = tf.train.Saver([tf_db])
    with tf.Session() as session:
      session.run(tf.global_variables_initializer())
      saver.save(session, ckpt_path)

path = 'home/Desktop/checkpoints/'
temp = ['1','2','3']
savecheckpoint("coref", np.array([m[0] for m in temp], dtype=np.int32), tf.int32, os.path.join(path, "var.npz"))

I am new to PyTorch, I have tried to convert above mentioed code in PyTorch:
import os
import torch
import numpy as np

def write_to_checkpoint(var_name, np_db, dtype, checkpoint_path):
    """Write np array to checkpoint."""
    t_db = torch.from_numpy(np_db)
    checkpoint = {
        var_name:t_db
    }
    torch.save(checkpoint,checkpoint_path+var_name+'.pth')

Are these codes equivalent? If not then please suggest correct equivalent codes.

Context:
Welcome to the TF community forum.
As It Is more related to pytorch I suggest to post the same on:

      PyTorch Forums

PyTorch Forums 3

  A place to discuss PyTorch code, issues, install, research


Regarding the discrepancy between the loss of test_on_batch () and train_on_batch () after re-compile ()

Question:
Doing compile () twice (whether intentionally or accidentally) dissociates the losses of test_on_batch () and train_on_batch ().
Below is the source code that reproduces this phenomenon.
import os

os.environ["PYTHONHASHSEED"]=str(1234)

import numpy as np
import unittest
from tensorflow.keras.models import Model
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Input, Dense, Activation, Dropout
from tensorflow.keras.layers import BatchNormalization
from tensorflow.keras.models import load_model
import tensorflow as tf
import random as python_random

np.random.seed(123)

python_random.seed(123)

tf.random.set_seed(1234)

initializer = tf.keras.initializers.GlorotUniform(seed=42)

def get_model():
  model = Sequential()
  model.add(Input(shape=(3,)))
  model.add(BatchNormalization())
  model.add(Dense(10,kernel_initializer=initializer))
  model.add(BatchNormalization())
  model.add(Activation('relu'))
  model.add(Dense(4,kernel_initializer=initializer))
  model.compile(optimizer='adam', loss='mean_squared_error')
  model.summary()
  return model

x_data = [
[0.0, 0.0, 0.0],
[0.0, 0.0, 1.0],
[0.0, 1.0, 0.0],
[0.0, 1.0, 1.0],
[1.0, 0.0, 0.0],
[1.0, 0.0, 1.0],
[1.0, 1.0, 0.0],
[1.0, 1.0, 1.0],
]

y_data = [
[0.0, 0.0, 0.0, 1.0],
[0.0, 1.0, 1.0, 1.0],
[0.0, 1.0, 1.0, 1.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 1.0, 1.0, 1.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[1.0, 1.0, 1.0, 0.0],
]

x_data_keras = np.array(x_data)
y_data_keras = np.array(y_data)

max_loop = 500

# training 1
model = get_model()
for i in range(max_loop):
    result_pre = model.test_on_batch(x_data_keras, y_data_keras)
    result_train = model.train_on_batch(x_data_keras, y_data_keras)
    result_post = model.test_on_batch(x_data_keras, y_data_keras)
    print(result_pre, result_train, result_post)
for i in range(max_loop):
    result_pre = model.test_on_batch(x_data_keras, y_data_keras)
    result_train = model.train_on_batch(x_data_keras, y_data_keras)
    result_post = model.test_on_batch(x_data_keras, y_data_keras)
    print(result_pre, result_train, result_post)
print()

# training 2
model = get_model()
for i in range(max_loop):
    result_pre = model.test_on_batch(x_data_keras, y_data_keras)
    result_train = model.train_on_batch(x_data_keras, y_data_keras)
    result_post = model.test_on_batch(x_data_keras, y_data_keras)
    print(result_pre, result_train, result_post)
model.compile(optimizer='adam', loss='mean_squared_error')     # re-compile
print('re-compile')
for i in range(max_loop):
    result_pre = model.test_on_batch(x_data_keras, y_data_keras)
    result_train = model.train_on_batch(x_data_keras, y_data_keras)
    result_post = model.test_on_batch(x_data_keras, y_data_keras)
    print(result_pre, result_train, result_post)
print()

A part of the output result is put below.
Layer (type)                 Output Shape              Param #
=================================================================
batch_normalization (BatchNo (None, 3)                 12
_________________________________________________________________
dense (Dense)                (None, 10)                40
_________________________________________________________________
batch_normalization_1 (Batch (None, 10)                40
_________________________________________________________________
activation (Activation)      (None, 10)                0
_________________________________________________________________
dense_1 (Dense)              (None, 4)                 44
=================================================================
Total params: 136
Trainable params: 110
Non-trainable params: 26
_________________________________________________________________
0.6977941393852234 1.1270804405212402 0.6935483813285828
0.6935483813285828 1.1136053800582886 0.6893106698989868
0.6893106698989868 1.1002421379089355 0.6850830316543579
0.6850830316543579 1.0869929790496826 0.6808691620826721
0.6808691620826721 1.0738604068756104 0.6766723990440369
:
:
0.03179752826690674 0.03175930678844452 0.031733617186546326
0.031733617186546326 0.03169688582420349 0.031668905168771744
0.031668905168771744 0.03162558749318123 0.03159947693347931
0.03159947693347931 0.031562428921461105 0.03153043985366821
0.03153043985366821 0.03150099143385887 0.03146739304065704

Model: "sequential_1"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
batch_normalization_2 (Batch (None, 3)                 12
_________________________________________________________________
dense_2 (Dense)              (None, 10)                40
_________________________________________________________________
batch_normalization_3 (Batch (None, 10)                40
_________________________________________________________________
activation_1 (Activation)    (None, 10)                0
_________________________________________________________________
dense_3 (Dense)              (None, 4)                 44
=================================================================
Total params: 136
Trainable params: 110
Non-trainable params: 26
_________________________________________________________________
0.6977941393852234 1.1270804405212402 0.6935483813285828
0.6935483813285828 1.1136053800582886 0.6893106698989868
0.6893106698989868 1.1002421379089355 0.6850830316543579
0.6850830316543579 1.0869929790496826 0.6808691620826721
0.6808691620826721 1.0738604068756104 0.6766723990440369
:
:
0.001201115665026009 0.00034435521229170263 0.001191912218928337
0.001191912218928337 0.00033795437775552273 0.0011880495585501194
0.0011880495585501194 0.0003311052278149873 0.0011792024597525597
0.0011792024597525597 0.0003247302083764225 0.0011489215539768338
0.0011489215539768338 0.000317717669531703 0.0011202542809769511

training 1 does train_on_batch () 1000 times.
The final loss at the 1000th time is 0.03153043985366821 0.03150099143385887 0.03146739304065704, and there is little difference between the losses shown by test_on_batch () and train_on_batch ().
training 2 does 500 train_on_batch (), compile (), and 500 more train_on_batch ().
The final loss for the 1000th time is 0.0011489215539768338 0.000317717669531703 0.0011202542809769511, which is an order of magnitude different. (The difference in loss is getting bigger and bigger.)
Do you know what causes this phenomenon?
And if this happens, how can I avoid it?

Context:
Using the same model instance I think that you need to manually reset your model weights:

      github.com/keras-team/keras

      Re-init weights to avoid recompile 1

        opened

        Aug 28, 2015

          closed

        Jun 25, 2021

          PilCAki

    If you'd like to average NN's with different inits, currently there is no easy m…ethod for getting a different random init of weights without recompiling.

Currently, I can train nets on medium sized data in about 1 minute but it sometimes takes several minutes to compile if I've got particularly complex structure.

It's possible to save the weights and re-init with the original weights.  However, there should be method to reset to a "like-new" state non-identical to first init without having to recompile.


Question:
I installed tensorflow with pip install tensorflow-gpu (tensorflow-gpu-2.6.0)
I followed these steps 21 to install CUDA:

image1126×564 44.8 KB

but when I’m trying to run my tensorflow code I’m getting:

I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-09-10 19:48:31.318358: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcusolver.so.11'; dlerror: libcusolver.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/lib64/openmpi/lib/:/usr/local/cuda/lib64:/usr/local/lib:/usr/lib:/usr/local/cuda/extras/CUPTI/lib64:/usr/local/mpi/lib:/lib/:/usr/local/cuda/lib64:/usr/local/lib:/usr/lib:/usr/local/cuda/extras/CUPTI/lib64:/usr/local/cuda/lib:/opt/amazon/efa/lib:/usr/local/mpi/lib:/opt/amazon/openmpi/lib:/usr/lib64/openmpi/lib/:/usr/local/cuda/lib64:/usr/local/lib:/usr/lib:/usr/local/cuda/extras/CUPTI/lib64:/usr/local/mpi/lib:/lib/:
2021-09-10 19:48:31.319345: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1835] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...

and when I check GPUs with print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU'))) it’s:
Num GPUs Available:  0
I am using Python 3.7.7

Context:
For Cuda 11.4 you can subscribe and upvote to:

      github.com/tensorflow/tensorflow

      Upgrade TF to CUDA 11.4 and cuDNN 8.2  68

        opened

        Aug 25, 2021

          pkanwar23

        type:build/install

    Upgrade TF to CUDA 11.4 and cuDNN 8.2

I think TensorFlow 2.6.0 is on CUDA 11.2


Question:
When I have a small dataset I’m fitting my model like that:
model.fit(
train,
train_labels,
epochs=200,
validation_split=0.2,
batch_size=100,
callbacks=[es],
use_multiprocessing=True
)

but now I can’t load the whole train set in one time as it’s too large, and wonder how I can fit this train set part by part to model?
(if I only can load train_part_1, train_part_2, train_part_3 from disk separately)

Context:
Hi Ashley,
What you are trying to do is to use batch_size properly.
If you have your pipeline of data using tf.data.Dataset (tf.data.Dataset  |  TensorFlow Core v2.6.0 9) it will load the data from disk for you and provide it for the model in chunks that fit the memory. Of course the size of these chunks it’s up to you to define.
This is a great tutorial to give more insights: Better performance with the tf.data API  |  TensorFlow Core 16


How to predict using TensorflowDecision Tree?

Question:
Hi,
How can I predict Labels using Tensorflow’s Decision Tree?
I have attached all the steps that I’ve done so far.

image708×521 21.1 KB

Thank you

Context:
If you call model.predict(), it should output class probabilities (number of columns is equal to the number of classes). You can apply tf.math.argmax() to it - it will produce the indexes of largest value in each row (highest probability). Presumably you have a list of labels for all classes. Use the indexes to get the class label for each sample in our dataset.
If your classification task is binary, model.predict() should output one value between 0 and 1 for each sample. In that case you can use 0.5 or some other threshold to decide if it’s class 0 or class 1.


Question:
Hey there i’m trying to build a toy ResNet model, but i’m facing this Error:
TypeError: Failed to convert object of type <class ‘main.ResNetModel’> to Tensor. Contents: <main.ResNetModel object at 0x7f36645e2c18>. Consider casting elements to a supported type.TypeError: Failed to convert object of type <class ‘main.ResNetModel’> to Tensor. Contents: <main.ResNetModel object at 0x7f36645e2c18>. Consider casting elements to a supported type.

Context: Can you share your code?


How to utilize the latest XNNPack in TFJS-Lite?

Question:
In the recent blog post 5 XNNPack was shown to have accelerated processing via quantization and SIMD. I’d like to utilize these abilities via TFJS (WASM), though it is unclear exactly how to do so.
In the blog post they mention that, “will be available in TensorFlow Lite Web API 2 in the 2.7 release”, when will that release be available? If I wanted to try it now should I just build TFJS myself from nightly, or is it just not in the codebase yet?
Please let me know!
Michael Carlon

Context:
I think that you can build yourself with:

      github.com

tfjs/tfjs-tflite at master · tensorflow/tfjs - Building 5

  master/tfjs-tflite

  A WebGL accelerated JavaScript library for training and deploying ML models.


Design of a neural network for the analysis of the trajectory of people

Question:
Hello everyone,
I am taking my first steps in this interesting world of neural networks. I am currently involved in an interesting project where I need to obtain some previous results, where I think that a neural network would fit very well. However, I am a bit lost. That’s why I need some advice and/or some help. I’ll tell you about what we want to do to give you some context.
The project itself is framed within the theme of wellbeing in buildings. Specifically in the area of the occupancy level of the different rooms in a building. For this purpose, a multitude of devices have been deployed in the building (presence sensors, cameras, pressure sensors on chairs, electricity consumption meters, etc.) whose information will be, after being properly processed, combined and interpreted through symbolic knowledge.
One of the devices that has been deployed, the source of this post, is a Kinect. Through Kinect and its SDK, we store the coordinates of the detected users’ joints and their orientation. The main purpose of the Kinect is to allow us to detect when someone leaves one room and enters another, identifying the rooms of origin and destination. Below I show a figure from the perspective of the Kinect.

photo_2021-09-09_10-52-481280×960 112 KB

In the following code snippet I show an example of data stored in JSON. In this way, every time a user changes room, we will obtain a set of frames composed by the position (reference system in the Kinect) of the SPIN_BASE joint (taken as a reference in this work) and its orientation. We consider that tracking that single coordinate is enough, allowing us to reduce the necessary computation.
{
  "skeleton_id": "id_123456789",
  "frames": [
    {
      "timestamp": VALUE,
      "point": {
        "x": VALUE,
        "y": VALUE,
        "z": VALUE
      },
      "orientation": {
        "x": VALUE,
        "y": VALUE,
        "z": VALUE,
        "w": VALUE
      }
    },

    ...

    {
      "timestamp": VALUE,
      "point": {
        "x": VALUE,
        "y": VALUE,
        "z": VALUE
      },
      "orientation": {
        "x": VALUE,
        "y": VALUE,
        "z": VALUE,
        "w": VALUE
      }
    }
  ]
}

My difficulties come when designing a neural network that is able to learn patterns to identify the source and destination rooms of users through these sets of (points, orientations). I have spent several weeks documenting myself and I have drawn some conclusions:

The order of the data in this case is of great importance, so the best option is an RNN.

I assume that the data should be pre-processed to make it more representative. Apart from the usual (such as normalisation), I think it should be processed in some way - perhaps represent the sets of points as trajectories?

Due to my limited experience, I am lost in network design and data preparation. So any help or advice would be very welcome.

Context:
HI,
This is what I’d do:

create a model that given a sequence of positions, predicts the next (x,y) position based on historical data.
make this model generate a maybe 10 points ahead and use this generated path decide to which room the person is going.

the part about deciding the room I’d do in regular code for now (is (x,y) inside room 1?)
to do that I’d try using RNN (or LSTM to be more precise) and look into how to predict any time series (eg: weather). My gut suggest that they are similar problems.
For example, here’s a video of a friend doing some basics on trajectory prediction: Shooting Hoops with Keras and TensorFlow || Zack Akil - YouTube 3
(it’s old but it’s just to get the idea)
I hope this can give you some ideas.


Tensorflow js - tfjs-examples error in tfjs-node

Question:
I have Mac Catalina, I start running the tfjs-examples : I tried 3 examples 1) addition-rnn, 2)date-conversion-attention 3)jena-weather
doing $yarn build  or $yarn train  - not able to resolve this error ( I even installed xcode as suggested)

Get this error var node2 = new Node();
for (var key in this) {
// Do not clone comments tha…… } could not be cloned.
var node2 = new Node();
for (var key in this) {
// Do not clone comments tha…… } could not be cloned
51 packages are looking for funding
run npm fund for details
found 5 vulnerabilities (1 low, 4 moderate)
run npm audit fix to fix them, or npm audit for details
(base) cyrils-mbp:addition-rnn cyrilfurtado$ npm audit fix
npm WARN vega-embed@6.8.0 requires a peer of vega@^5.8.0 but none is installed. You must install peer dependencies yourself.
npm WARN vega-lite@4.13.1 requires a peer of vega@^5.12.1 but none is installed. You must install peer dependencies yourself.
npm WARN vega-themes@2.10.0 requires a peer of vega@* but none is installed. You must install peer dependencies yourself.

Context: Thanks for posting on the forum! I just tried this myself, and I’ve run into the same build failure as you’re seeing. Would you like to post this as a bug in the tfjs GitHub repository 8? That will help the team track and triage the issue. If not, I’m happy to create the bug report myself.


For a tensorflow public function, is there a way to link the script that it is in and the function name?

Question:
Hi, new Tensorflow user here. I am studying Tensorflow source code and have a very specific question. For every public function, I want to get the source code equivalent of it. https://www.tensorflow.org/api_docs/python/tf/all_symbols I tried using this but in the source code, public functions are named differently compared to the API symbols.
Example:

This is in the python file tensor_util. https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/framework/tensor_util.py#L809-L885
Is it possible to form the connection between source code and API symbols? For example, with the picture above, I want to connect tensor_util.constant_value to tf.get_static_value and retrieve all the source code equivalent of the public API symbols.

Context:
You can try using some of the helpers in tf_export.py:
from tensorflow.python.util.tf_export import get_symbol_from_name

get_symbol_from_name('get_static_value')

Returns:
<function tensorflow.python.framework.tensor_util.constant_value>

You can then use the functions __code__ property to extract whatever information you’re looking for. Here’s a function that prints out an API function’s name, module name, file name, and definition line number:
from tensorflow.python.util.tf_export import get_symbol_from_name

def print_api_info(api_name):
  func = get_symbol_from_name(api_name)
  if func is not None:
    module = func.__module__
    code_object = func.__code__
    fname = code_object.co_filename
    line_no = code_object.co_firstlineno
    name = code_object.co_name
    print(f'Name: {name}\nModule: {module}\nFile: {fname}\nLineNo: {line_no}\n')

Trying with your example:
print_api_info('get_static_value')

Prints:
Name: constant_value
Module: tensorflow.python.framework.tensor_util
File: /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/tensor_util.py
LineNo: 809

EDIT: api_name should contain the full namespace within TensorFlow. e.g. for tf.autograph.set_verbosity, you would do:
print_api_info('autograph.set_verbosity')

I’m not certain if this will be useful for every function in the API, but it might be a start in navigating around the source.


Is it possible to recognize thousands of individual fish?

Question:
Hi all! I usually work with web application development, but I’ve been asked by a potential customer if it’s possible to create a CNN which is able to recognize thousands of individual fish. I know that e.g. Google Photos does the same for faces and even individual pets, so I know that it’s possible. What I don’t know is if its possible to do so without Google’s resources?
All examples I’ve read/watched so far in regards to face recognition is about how the CNN can recognize the faces of persons it already knows (i.e. you teach it from 20 labeled images that George W. Bush looks like this, and then it can identify him on any photo after that.) But how does Google do it when they don’t know the names of the persons (images are not labeled), and they still manage to group the images of each individual person/pet so that the user can label them afterwards?
My guess is that they’ve trained their CNN on millions of images, and if the image at hand doesn’t match any of the pre-trained individuals, they put it in a new group called “Unknown person nr xxx”. If they later come across a second image of the same face, it will be placed in that same group. Is this a correct assumption? If yes, does this mean that to be able to identify thousands of individual fish, you need to train a model with xxx images of yyy individual fish before the model is ready for use? If we assume that individual fish are as diverse as human faces, how many training images would one need per fish, and how many individual fish, if you wanted an accuracy > 80%?

Context:
Hi Anders,
Do you want to recognize an individual fish or a type of fish (salmon vs shark?)??
in any of the cases, you’d need many many images of fish to train the model.
On the faces feature you mentioned, what I think they are doing is, they know how to find a face on a picture. That’s kind of easy as faces are usually all similar (eyes, nose, mouth). After that, you can calculate an embedding and use something like nearest neighbors to find similar faces and create groups of faces that are from the same person.
This same algorithm can be used for a lot of things, not only faces.
I hope it helped


Question:
Hi.
I have a test dataset with 285 columns.
As I understand it is mean that I need 284 input as X and 1 column for Y as result.
I have only 40 output options, so NN has 40 output shape.
This is my code in python:
def get_x(dataset):
    X = dataset.iloc[:,1:285].values
    return X

def get_y(dataset):
    y = dataset.iloc[:,285:286].values
    return y

def make_nn():
    output = 40
    model = Sequential()
    model.add(Dense(284, input_dim=284, activation='softmax'))
    model.add(Dense(284, activation='softmax'))

    model.add(Dense(output, activation='softmax'))
    for i in range(250):
        model.add(Dense(284, activation='softmax'))
    model.add(Dense(40, activation='softmax'))
    model.summary()

    model.compile(loss='categorical_crossentropy', optimizer='adamax', metrics=['accuracy'])
    return model

def train_nn(dataset, model):
    x=get_x(dataset)
    y=get_y(dataset)

    X_train,X_test,y_train,y_test = train_test_split(x,y,test_size = 0.1,random_state = 0)
    output = 40
    y_train_cat = keras.utils.to_categorical(y_train, output)
    y_test_cat = keras.utils.to_categorical(y_test, output)

    model.fit(X_train, y_train_cat ,validation_data = (X_test,y_test_cat), epochs=1000, batch_size=6068)

dataset=get_dataset('test.csv')
model=make_nn()
for i in range(50):
    train_nn(dataset, model)
    print("Save model")
    model.save('model/model.test.h5')

But when I run it, I see information like this:
Epoch 1/10
2/2 [==============================] - 31s 8s/step - loss: 3.6861 - accuracy: 0.0721 - val_loss: 3.6820 - val_accuracy: 0.0597
I haven’t seen that accuracy exceeded 0,14. As I understand, it is too small number.
Loss  was also not less than 2ю
What am I doing wrong? Any advice, please?
Also, what is better: big batch_size or small?

Context: No sure where’s the issue but why are you adding 250 Dense layers to your model?


How to dive deep into Tensorflow internals

Question: I want to read the source code of tensorflow and understand internals. But tensorflow is a complex project, I find it is hard for me to dive deep into it. Are there any recommended docs or lectures to help me understand the internals?

Context: How about: Inside TensorFlow - YouTube 14


Question:
I trained the MobilenetV3 model with the input of range [-1,1] by passing the argument
include_preprocessing = True
Then, while the model is predicting with the
var output = await Tflite.runModelOnImage(
      path: image.path,
      numResults: 14,
      imageMean: 127.5,
      imageStd: 127.5,
);

function on TFLite, it always predicts the same class.
Colab Link of the model 3

Context:
Hi,
Just to have some more info, did you follow a tutorial? can you share the link?
where did you get the [-1, 1] range?
are you running this on JS?
the colab link needs permission, maybe if you put on a public repository it would be easier to share on this forum.


Improvement of API: Measures to avoid ValueError when pruning low manitude

Question:
Dear developers,
I have been try out the guide on pruning models (Pruning comprehensive guide  |  TensorFlow Model Optimization 3). My experiment is to prune a model with different schedules continuously. Therefore I wrote code like this:
params1 = {
         'pruning_schedule': tfmot.sparsity.keras.PolynomialDecay(initial_sparsity=0.5,
                                                                        final_sparsity=0.9,
                                                                        begin_step=0,
                                                                        end_step=10000)
}

params2 = {
         'pruning_schedule': tfmot.sparsity.keras.ConstantSparsity(
                                                                        0.75,
                                                                        begin_step=0,
                                                                        end_step=-1)
}

model1 = prune_low_magnitude(base_model, **pruning_params)

model_for_pruning.compile(optimizer='adam',
        loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
        metrics=['accuracy'])

def apply_pruning(layer):
         return tfmot.sparsity.keras.prune_low_magnitude(layer, params2)

model_2 = tf.keras.models.clone_model(model1, clone_function=apply_pruning)

Then I got a ValueError:
Please initialize `Prune` with a supported layer. Layers should either be supported by the PruneRegistry (built-in keras layers) or should be a `PrunableLayer` instance, or should has a customer defined `get_prunable_weights` method. You passed: <class 'tensorflow_model_optimization.python.core.sparsity.keras.pruning_wrapper.PruneLowMagnitude'>

I know that it is because some layers that cannot be pruned is passed to prune_low_magnitude. I solved it with add an if isinstance(layer, tf.keras.layers.Dense). But I think the handler could be more friendly than just a critical error. Perhaps just ignore this kind of layers or report a warning is better.
BTW, if isinstance(layer, tf.keras.layers.Dense) seems to bypass the layers pruned before. Is there any solutions if I just want to prune the same layer using PolynomialDecay and ConstantSparsity successively? Thank you.

Context: Adding @Rino_Lee for the visibility


Checkpoints does not seem to change (eager tflite example)?

Question:
Looking at the example here Few Shot Object Detection for TensorFlow Lite 1 the checkpoint files that are generated seems to be the same? At least their file size appear to be equal:
drwxr-xr-x 3 root root     4096 Sep  5 10:34 ..
-rw-r--r-- 1 root root 10476721 Sep  5 10:38 ckpt-2.data-00000-of-00001
-rw-r--r-- 1 root root    26198 Sep  5 10:38 ckpt-2.index
drwxr-xr-x 2 root root     4096 Sep  5 10:38 .ipynb_checkpoints
-rw-r--r-- 1 root root 10476721 Sep  5 10:39 ckpt-3.data-00000-of-00001
-rw-r--r-- 1 root root    26198 Sep  5 10:39 ckpt-3.index
-rw-r--r-- 1 root root 10476721 Sep  5 10:40 ckpt-4.data-00000-of-00001
-rw-r--r-- 1 root root    26198 Sep  5 10:40 ckpt-4.index
-rw-r--r-- 1 root root 10476721 Sep  5 10:40 ckpt-5.data-00000-of-00001
-rw-r--r-- 1 root root    26198 Sep  5 10:40 ckpt-5.index
-rw-r--r-- 1 root root 10476721 Sep  5 10:41 ckpt-6.data-00000-of-00001
-rw-r--r-- 1 root root    26198 Sep  5 10:41 ckpt-6.index
-rw-r--r-- 1 root root      519 Sep  5 10:41 checkpoint

The only thing I have changed is that I have put the saving of checkpoint for each 100 step like so and set the number of checkpoints to keep (max_to_keep) to 5:
  if idx % 100 == 0:
    print('batch ' + str(idx) + ' of ' + str(num_batches)
    + ', loss=' +  str(total_loss.numpy()), flush=True)
    ckpt_manager.save()

Shouldn’t the file size of the checkpoints differ since the weight values changes?

Context:
To answer this.
Even thought the size of the checkpoint does not change, the values of the variables in the checkpoint file in fact does change.


Question:
Hi, I am really new to machine learning and have been playing around with an example from a book. Some models are trained with CGI datasets, and the Rock, Paper, Scissors Dataset works pretty well when I use it to predict real world images.
I tried to replicate training with CGI images using images I rendered myself and I am struggling to understand why my two similar datasets give wildly different results.
Dataset 1 2 works really well when using real world images 1, classifying all but one image correctly. But the other Dataset 2 1 does not work at all, with only one or two images correctly classified.
I randomly split the dataset into 20% validation and 80% training data. The code for training is here 1.
Is it pure luck that makes Dataset 1 work so well or is there a fundamental flaw in my understanding?
Thank you for advice.

Context: Link for dataset 2 is this one. 1. As I am a new user I can not edit my first post because I can only post 2 links.


Question:
I trained my model on some set of labeled images, where I have ‘label_1’, ‘label_2’, ‘label_3’
Then, I’m trying to predict labels of unknown images with features = model.predict(images)
but here I only obtain feature maps, not labels themselves. How can I do label = decode_predictions(features) to get actual name of labels?

Context:
Hi @Ashley,
If you are using softmax activation function at the last classification dense layer,  model.predict(images) is going to return the prediction scores for all classes/labels.
You can get the prediction scores by model.predict(image)[0], and then get the index of the maximum score by using np.argmax() or tf.math.argmax().
Here is a typical example from loading an image to getting its predicted label
image = tf.keras.preprocessing.image.load_img(image_path, target_size=(224,224))
image = tf.keras.preprocessing.image.img_to_array(image)
image = image/255.0
image = tf.expand_dims(image, 0)

# predict the image

pred = model.predict(image)

# Get the label/class

im_class = tf.argmax(pred[0], axis=-1) #either tf.math.argmax() or tf.argmax will work

If you are using a specific pre-trained model from Keras directly, you can refer to some examples from the documentation on how to get the class using
decode_predictions()
Hope that helps!


Question:
Opening this thread so that people can post the arxiv links of some of the famous papers of deep learning. This thread may help beginner in deep learning to cope up.
You can send the link and also mention the high level research topic for which the paper has been famous. (See the below example).
Topic: Generative Adversarial Networks (GANs)
Paper: GAN paper 4

Context:
Nice idea @ashutosh1919
Topic: Core Deep Learning

Deep Learning (LeCun, Bengio & Hinton, 2015) 9 (Nature)
A Fast Learning Algorithm for Deep Belief Nets (Hinton, Osindero & Teh, 2006) 7

Reducing the dimensionality of data with neural networks (Hinton & Salakhutdinov, 2006) 9 (Science)

Learning representations by back-propagating errors (Rumelhart, Hinton & Williams, 1986) 8 (Nature)


Question:
i want use MaxUnPooling2D in an autoencoder like this code
input_img = Input(shape=(nr_col, nr_rows, 1))
ec_conv1 = Conv2D(N[0], (3,3), activation=‘relu’, padding=‘same’)(input_img)
ec_ouput = MaxPooling2D((2, 2), padding=‘same’)(ec_conv1)
z=Flatten(name=‘VC’)(ec_ouput)
r=Reshape((24,24,N[0]),name=‘Resh’)(z)
dec_conv1 = Conv2D(N[0], (3, 3), activation=‘relu’, padding=‘same’)(r)
dec_upsample1 = tfa.layers.MaxUnpooling2D((2, 2), padding=‘SAME’)(dec_conv1)
dec_output = Conv2D(1, (3,3), activation=‘sigmoid’, padding=‘same’)(dec_upsample1)
autoencoder = Model(input_img, dec_output)
autoencoder.summary()
autoencoder.compile(optimizer=‘adam’, loss=‘binary_crossentropy’, metrics = [‘acc’])  #binary_crossentropy
autoencoder_history = autoencoder.fit(x_train, x_train,batch_size=batch_size,epochs=epochs, verbose=1,validation_data=(x_val, x_val))
But i get an this error
TypeError: in user code:  TypeError: tf__call() missing 1 required positional argument: 'mask'
Any help ?

Context: Please update TF Addons version to the last One


Dataset for concentration analysis and liveness check of subject during video calls

Question: I am looking for datasets that might help with training a ML model for identifying whether the subject in front of camera is real or fake and also to identify whether the subject is concentrating in the meeting.Any help is really appreciated.

Context:
I think you can start to take a look at something similar like driver distraction/fatigue datasets/papers as I think you will find more material in the literature on that domain.
In your case, one of the solution you can try to explore, is to unify an adversarial detection network 2 with a distracting/fatigue detector or a action recognition like e.g. MoVinets 1.
Probably if you can combine to train a single network on these two tasks it will be better but I think that you need to collect your own dataset.


Question:
On a PC with NVIDIA GeForce RTX 2060 and Ubuntu version 20, when running the following code:
import tensorflow as tf device_name = tf.test.gpu_device_name()
I am advised to follow the instructions at this link 3 because:
Could not load dynamic library ‘libcusolver.so.11’; dlerror: libcusolver.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda-11.2/lib64
Those instructions did not solve the issue,
However the guide covers ubuntu version 16 and 18

Context:
Can you make the same test in our Docker image?

      TensorFlow

Docker  |  TensorFlow


Model to generate very long text sequences

Question: I’ve recently downloaded TensorFlow with the intent of using it via PyCharm. I’m seeking to have an AI learn to write a television script, as is popular on the internet these days, and initially found this 2 tutorial. It is, of course, very outdated, and not useable with my Windows PC, but was useful in giving me a pre-written code, where I simply had to replace the input text with my own. It seems that the code as a whole, though, is contained within a folder, rather than any individual file, and I haven’t been able to figure out how to import this training code into the program. Does anyone know how I could manage?

Context:
Hi,
To give you some more resources on generating text:

Text generation with an RNN  |  TensorFlow 5
Verse to Verse (for ideas): Verse by Verse

also, it would be good to also take a look on using Google Colab 1 for development. It’s a free env that makes managing dependencies very easy.


How to convert a tensor to a numpy array without enabling the run_eagerly flag in keras

Question:
I am writing my own metric call-back functions where I use sklearn to calculate the metrics and for that I need to have the y_true and y_pred tensors as numpy arrays. My functions look like this:
def precision_macro(y_true, y_pred):
    # get the y_true and y_pred tensors as 1-D numpy array
    y_true_array = np.array(true)
    y_pred_array = np.array(pred)
    ....................
    ....................
        CALCULATIONS
    ....................
    ....................
    precision = precision_score(y_true_array, y_pred_array, average="macro", zero_division=0)
    return precision

Everything works fine if I set the run_eargly=True during the compile call like this:
model.compile(optimizer=keras.optimizers.RMSprop(learning_rate=lr),
                      loss='binary_crossentropy',
                      metrics=model_metrics,
                      run_eagerly=True)

but this is very costly and way slower than with the flag set to False but if I don’t set the flag to True I have a problem with the conversion. Here are things I have tried without setting the run_eagrly flag to True and didn’t work:
If I just don’t set the run_eagerly flag, I get the following error

NotImplementedError: Cannot convert a symbolic Tensor (ExpandDims:0) to a numpy array. This error may indicate that you’re trying to pass a Tensor to a NumPy call, which is not supported

Then I tried
import tensorflow.keras.backend as K

def precision_macro(y_true, y_pred):
    # get the y_true and y_pred tensors as 1-D numpy array
    y_true_array = K.eval(y_true)
    y_pred_array = K.eval(y_pred)
    ....................

Or I try to call the numpy function on the tensors
def precision_macro(y_true, y_pred):
    # get the y_true and y_pred tensors as 1-D numpy array
    y_true_array = y_true.numpy()
    y_pred_array = y_pred.numpy()
    ....................

I also tried run this inside a session like this:
import tensorflow.keras.backend as K
import tensorflow as tf

def precision_macro(y_true, y_pred):
    sess = tf.compat.v1.Session()
    # get the y_true and y_pred tensors as 1-D numpy array
    with sess.as_default():
       y_true_array = K.eval(y_true)
       y_pred_array = K.eval(y_pred)
    ....................

I get the following error for all thress cases

AttributeError: ‘Tensor’ object has no attribute ‘numpy’

I tried to run it like this:
import tensorflow.keras.backend as K
import tensorflow as tf

def precision_macro(y_true, y_pred):
    sess = tf.compat.v1.Session()
    # get the y_true and y_pred tensors as 1-D numpy array
    with sess.as_default():
       y_true_array = sess.run(y_true)
       y_pred_array = sess.run(y_pred)
    ....................

I get the following error

InvalidArgumentError: 2 root error(s) found.
(0) Invalid argument: You must feed a value for placeholder tensor ‘iterator’ with dtype resource
(1) Invalid argument: You must feed a value for placeholder tensor ‘iterator’ with dtype resource

I tried downgrading numpy from 1.19.5 to 1.18.5 but that didn’t work either, I get the same errors
I am using keras = 2.6. tensorflow = 2.6 numpy = 1.19.5
So, can anybody help me ?

Context:
Why you don’t implement your custom metric composing TF ops if you want to run in graph mode?
See also Custom metrics section in:

      keras.io

Keras documentation: Metrics 20


Question:
I’m seeing slow object detection inference times on models trained using the efficientdet_lite0.
I’m using the TF Lite model maker example notebook for object detection 6 with a custom dataset and am seeing inference times of 1.5-2 seconds on my MacBook Pro (single thread, no GPU). I can bring this down to around 0.75s with num_threads set to 4 but this seems to be much greater than the 37ms latency the notebook mentions. I thought it could be caused by overhead loading the model but subsequent calls to the interpreter.invoke method yield similar performance. My perf measurement is v basic, using time.perf_counter() either side of the invoke call. I’m quite new to all this so I feel like I’m doing something obviously wrong? Or am I missing something with post-training quantization?
In Google colab I’m seeing similar performance with the default notebook using the dataset provided in the notebook.

Context:
HI Nick,
in the colab test you did, is the runtime using a GPU? this can make a big difference.


TensorFlow C++ API: Guides/Documentation?

Question:
Hi there,
I’m pretty new in regards to TensorFlow and am currently trying to figure out how to work with the C++ API of TensorFlow and how functional it is for my use case(see below).
However it seems, that the official guides and most of online documentation focus on the python implementation. This is not usable for me though, since I need to work with C++ only.
Is there some form of (un)official documentation for the C++ API which explains how to use it properly?
So far I was only able to load my model with the help of this explanation 4:
However I would like to be able to know how to properly work with the underlying layers in C++.
If this is possible at all.
Thank you for any form of help you might provide.
My use-case:
In a first step, I would like to be able to load a pretrained model in C++ and just connect input and output respectively to my underlying program.
As a second step, I would like to find out, if it is possible to “slice” the pretrained model into its layers, feed it with extracted weights of the pretrained model and connect these layers in a way, that I end up with a model, where each layer is represented by its own program, while the weights from the pretraining would still retain its original function.
Kind Regards,
Marco

Context:
You can see some good example about manipulating Tensorflow C API at:

      github.com

GitHub - serizba/cppflow: Run TensorFlow models in C++ without installation and... 16

  Run TensorFlow models in C++ without installation and without Bazel - GitHub - serizba/cppflow: Run TensorFlow models in C++ without installation and without Bazel

You can access to layer weights with:

      github.com/serizba/cppflow

      How to extract weights from saved model? 4

        opened

        Dec 7, 2020

          abucka

    Hi!

How can I extract weights from the saved model?

I am looking for the …equivalent of Python model.get_weights() but in Tensorflow C API. Especially, I would like to extract the weights for the last convolutional layer.

Thank you!

If you want to use instead  TFlite or TFlite Micro for inference they already have their own c++ API documented.
But to manipulate TFlite weights for inference you could check:

      github.com/tensorflow/tensorflow

      How to modify weights in TFLite model and check effect on activation layer output, set_tensor helps only on input layers and not intermediate tensors. 2

        opened

        May 3, 2021

          closed

        May 21, 2021

          manp-git

        stat:awaiting response
        type:support
        stalled
        comp:lite
        TF 2.0

    How to modify weights in TFLite model and check effect on activation layer outpu…t for experimentation purpose, set_tensor helps reapply things only on input layers and not intermediate tensors.
I am ok doing in offline by extracting output of previous layer and convolving it with the extracted weights and biases of layer in consideration.
Please share if there is a command for that. Else how can I exactly replicate the convolution and activation process of that particular Resnet50 layer outside the model using python etc.
Using standard Resnet50- keras model, quantised by TFLite converter.

Targetting conv2_block1_2 for experimentation; able to extract output of previous conv block which is input to this (conv2_block1_1) along with weights (ReadVariableOp) and bias of conv2_block1_2 from the TFLite model.

Tensorflow 2.0

To just read weights in TFlite c++:

      stackoverflow.com

  How to get weights in tflite using c++ api? 5

  tensorflow-lite

  asked by

    马嘉林

  on 08:08AM - 21 May 20 UTC


Trying to modify person_detection.ino project to use my own model. Need help!

Question:
Hi all,
I’m looking to use the person_detection arduino script that you were the teacher for, but modify it to run my own network. Unfortunately, what I did is not working, and I keep getting “Invoke Failed()” errors on my Nano BLE 33. I was hoping you’d be able to help guide me in the right direction, and show me what I’m doing wrong.
Below is the procedure I follow, and attached is my tflite model file and my modified person detection project. The only two files within the project that I actually modify from the original are the person_detection.ino and the person_deteciton_model_data.cc.
Thank you in advance for your help!
Here is the procedure I followed:
1)Create a model with Teachable Machine 4

Download my model as a keras file

Convert from Keras model to tflite model, and then integer quantize the model using the code here: https://colab.research.google.com/drive/12O9qO6bAI72B0RTt88sQPkcHkC16Mb8O?usp=sharing

Convert from tflite to .cc using : xxd -i converted_model.tflite > model_data.cc

Replace value of g_person_detect_model_data_len with new value from my model_data.cc

Replace model_data with new model data from my model_data.cc

Use https://netron.app/ to visualize the network and see what MicroOpsResolvers need to be included. Include as necessary.

The only two files in the project that I touch at all are person_detection.ino and person_detection_model_data.cpp. Please help me figure out why it’s not working!!!
Here is my person_detection.ino file for you to look
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#include <TensorFlowLite.h>

#include "main_functions.h"

#include "detection_responder.h"
#include "image_provider.h"
#include "model_settings.h"
#include "person_detect_model_data.h"
#include "tensorflow/lite/micro/micro_error_reporter.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/version.h"

// Globals, used for compatibility with Arduino-style sketches.
namespace {
tflite::ErrorReporter* error_reporter = nullptr;
const tflite::Model* model = nullptr;
tflite::MicroInterpreter* interpreter = nullptr;
TfLiteTensor* input = nullptr;

// In order to use optimized tensorflow lite kernels, a signed int8_t quantized
// model is preferred over the legacy unsigned model format. This means that
// throughout this project, input images must be converted from unisgned to
// signed format. The easiest and quickest way to convert from unsigned to
// signed 8-bit integers is to subtract 128 from the unsigned value to get a
// signed value.

// An area of memory to use for input, output, and intermediate arrays.
constexpr int kTensorArenaSize = 136 * 1024;
static uint8_t tensor_arena[kTensorArenaSize];
}  // namespace

// The name of this function is important for Arduino compatibility.
void setup() {
  // Set up logging. Google style is to avoid globals or statics because of
  // lifetime uncertainty, but since this has a trivial destructor it's okay.
  // NOLINTNEXTLINE(runtime-global-variables)
  static tflite::MicroErrorReporter micro_error_reporter;
  error_reporter = &micro_error_reporter;

  // Map the model into a usable data structure. This doesn't involve any
  // copying or parsing, it's a very lightweight operation.
  model = tflite::GetModel(g_person_detect_model_data);
  if (model->version() != TFLITE_SCHEMA_VERSION) {
TF_LITE_REPORT_ERROR(error_reporter,
                     "Model provided is schema version %d not equal "
                     "to supported version %d.",
                     model->version(), TFLITE_SCHEMA_VERSION);
return;
  }

  // Pull in only the operation implementations we need.
  // This relies on a complete list of all the ops needed by this graph.
  // An easier approach is to just use the AllOpsResolver, but this will
  // incur some penalty in code space for op implementations that are not
  // needed by this graph.
  //
  // tflite::AllOpsResolver resolver;
  // NOLINTNEXTLINE(runtime-global-variables)
  static tflite::MicroMutableOpResolver<10> micro_op_resolver;

  micro_op_resolver.AddPad();
  micro_op_resolver.AddConv2D();
  micro_op_resolver.AddDepthwiseConv2D();
  micro_op_resolver.AddSoftmax();
  micro_op_resolver.AddRelu6();
  micro_op_resolver.AddRelu();
  micro_op_resolver.AddAdd();
  micro_op_resolver.AddMean();
  micro_op_resolver.AddFullyConnected();
  micro_op_resolver.AddQuantize();

  // Build an interpreter to run the model with.
  // NOLINTNEXTLINE(runtime-global-variables)
  static tflite::MicroInterpreter static_interpreter(
  model, micro_op_resolver, tensor_arena, kTensorArenaSize, error_reporter);
  interpreter = &static_interpreter;

  // Allocate memory from the tensor_arena for the model's tensors.
  TfLiteStatus allocate_status = interpreter->AllocateTensors();
  if (allocate_status != kTfLiteOk) {
TF_LITE_REPORT_ERROR(error_reporter, "AllocateTensors() failed");
return;
  }

  // Get information about the memory area to use for the model's input.
  input = interpreter->input(0);
}

// The name of this function is important for Arduino compatibility.
void loop() {
  // Get image from provider.
  if (kTfLiteOk != GetImage(error_reporter, kNumCols, kNumRows, kNumChannels,
                        input->data.int8)) {
TF_LITE_REPORT_ERROR(error_reporter, "Image capture failed.");
  }

  // Run the model on this input and make sure it succeeds.
  if (kTfLiteOk != interpreter->Invoke()) {
TF_LITE_REPORT_ERROR(error_reporter, "Invoke failed.");
  }

  TfLiteTensor* output = interpreter->output(0);

  // Process the inference results.
  int8_t person_score = output->data.uint8[kPersonIndex];
  int8_t no_person_score = output->data.uint8[kNotAPersonIndex];
  RespondToDetection(error_reporter, person_score, no_person_score);
}

Context:
I am exactly doing the same thing
when running I am getting following output
Didn’t find op for builtin opcode ‘DEPTHWISE_CONV_2D’ version ‘3’
Failed to get registration from op code  d
AllocateTensors() failed
Guru Meditation Error: Core  1 panic’ed (LoadProhibited). Exception was unhandled.
Core  1 register dump:
PC      : 0x400d2890  PS      : 0x00060d30  A0      : 0x800daa57  A1      : 0x3ffb2800
A2      : 0x3ffd3efc  A3      : 0x00000000  A4      : 0x3ffc16e0  A5      : 0x3ffc1638
A6      : 0x3ffc1640  A7      : 0x00000001  A8      : 0x800d2851  A9      : 0x3ffb27b0
A10     : 0x00000000  A11     : 0x00000060  A12     : 0x00000060  A13     : 0x00000001
A14     : 0x00011800  A15     : 0x3ffc1640  SAR     : 0x00000006  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000004  LBEG    : 0x40089029  LEND    : 0x40089039  LCOUNT  : 0xffffffff
Backtrace:0x400d288d:0x3ffb28000x400daa54:0x3ffb2820
ELF file SHA256: 0000000000000000
Rebooting…


Question:
Hello all!
I am following the tutorial about Time Series from the official documentation of TensorFlow (https://www.tensorflow.org/tutorials/structured_data/time_series 8), and I am facing difficulties caused by the occurrence of the error below (which also occurs in other code snippets that run later), when I apply my input data (time series), that has 1440 points, to the code, and I change the code to forecast 300 points in the future (OUT_STEPS = 300, label_width=OUT_STEPS,                           shift=OUT_STEPS, etc.), also adjusting the inputs to 300.
Here is one of the excerpts with which I have an error, and below, the output presented (error) from its execution:
Code executed:
history = compile_and_fit(lstm_model, wide_window)

IPython.display.clear_output()

multi_val_performance['AR LSTM'] = feedback_model.evaluate(multi_window.val)
multi_performance['AR LSTM'] = feedback_model.evaluate(multi_window.test, verbose=0)
multi_window.plot(feedback_model)

Output from execution:
/usr/local/lib/python3.7/dist-packages/keras/utils/generic_utils.py:915: RuntimeWarning: divide by zero encountered in log10
  numdigits = int(np.log10(self.target)) + 1
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
<ipython-input-63-8a2e627c43f4> in <module>()
      2
      3 IPython.display.clear_output()
----> 4 val_performance['LSTM'] = lstm_model.evaluate(wide_window.val)
      5 performance['LSTM'] = lstm_model.evaluate(wide_window.test, verbose=0)

4 frames
/usr/local/lib/python3.7/dist-packages/keras/utils/generic_utils.py in update(self, current, values, finalize)
    913
    914       if self.target is not None:
--> 915         numdigits = int(np.log10(self.target)) + 1
    916         bar = ('%' + str(numdigits) + 'd/%d [') % (current, self.target)
    917         prog = float(current) / self.target

OverflowError: cannot convert float infinity to integer

I concluded that there is some dependency between the number of data entry and the number of forecast points, but not what it would be, as if I set the number of forecast points to 300 points in the example of the TensorFlow website, with number of input like 70091 (considering df = df[5::6]), this type of error that I mentioned does not occur, but if I select only 1440 points, the same error that occurs applying my data of 1440 points also occurs. If you want you can check/edit the example code from the TensorFlow website, in which I set the input number 1440 points, and made the necessary settings to predict 300 points, here on this Google Colab 3.
Could you help me with this please?
Thanks in advance.

Context:
I can’t edit my post. I need to edit the first code. The right first code is the following:
history = compile_and_fit(lstm_model, wide_window)

IPython.display.clear_output()
val_performance['LSTM'] = lstm_model.evaluate(wide_window.val)
performance['LSTM'] = lstm_model.evaluate(wide_window.test, verbose=0)

Sorry for the error. I also posted a question about this in Stack Overflow: https://stackoverflow.com/questions/69059787/error-from-code-adapted-from-tutorial-about-time-series-forecasting-from-tensorf 33
Thanks.


Quantization aware model DepthWiseconv2D

Question:
I have a “DepthWiseconv2D” quantization support training Mobilenetv2 model.
Saved in the “Save Model” format.
It is possible to convert a saved model to TFLite.
QualComm SDK Command "SNPE-TENSORFLOW-TO-DLC] issues the following error:
KeyError: ‘__INERFERENCE_DEPTHWISE1_LAYER_CALL_FN_6443’
When checked with the “saved_model_cli” command, the following error occurs:
KeyError: ‘__inerence_depthwise_conv2d_layer_call_fn_978’
Why do you get an error? Is there a workaround?

Context:
I saved the “DepthWiseconv2D” model in the “Saved Model” format.
When checked with the “saved_model_cli” command, the following error occurs:
KeyError: ‘__inerence_depthwise_conv2d_layer_call_fn_978’
This problem is an error similar to the qualcomm’s SDK command “SNPE-TENSORFLOW-TO-DLC”.
Are “Save model” support “DepthWiseconv2D”?


How are Conv layer (and others layers) outputs quantized?

Question:
TensorFlow documentation says that during the inference step the weights and triggers are int8 and the bias is int32. The result of the convolution is added to the bias and then the result of the sum is converted from int32 bits to int8. This conversion is not clear to me. I think I would have some options for that. For example, we can use only the most significant or least significant bits to generate the output value in int8, or we can reduce the value and then convert to int8. So how is this conversion done?
I am developing an FPGA accelerator for CNN as a graduation work. I used Quantization Aware Training to get the 8-bit weights. I have extracted the quantized weights from the TFLite interpreter and am validating the weights in C before implementing in VHDL. However, the results aren’t correct and I think I’m missing something when converting the output of Conv Layer from int32 to int8.
Preformatted textchar o = (char)(conv_o + l.bias[m]); // add bias
Preformatted texto = (o < 0) ? 0 : o;                // RELU
I hope you can help-me.
Thank you!
Best regards.

Context: Adding @Jaehong_Kim for the visibility.


Clarification over Partial Run Feature of TensorFlow Graph

Question:
Hi All,
Let’s say I am building a graph representing the below equation.
p = x * y (x and y are integers and fed to the graph)
s = p + z(p is from above, z is a new input)
And I want to fetch both ‘p’ and ‘s’ from the graph session.
Now, I am trying to use the partial run feature of the graph where the results can be memoized internally in a session, my question is in the above equation if I keep changing only ‘z’, is the graph optimized to recompute only ‘s’ but not ‘p’ since the inputs to ‘p’ are not changing. Basically, does it evalute only the subgraph affected by the changed input and the rest stays as is.
Thanks.

Context: Any update on this topic?


How to test a model created with model_builder.build?

Question:
I am using a EfficientDet-D2 model in order to do some object detection. I have built the model like this:
self.model = model_builder.build(model_config = model_config,                                  is_training = True)
And the training seems to work fine (the loss is at least decreasing):
  @tf.function
  def train_step(self,image_tensors,groundtruth_boxes_list,groundtruth_classes_list):

    shapes = tf.constant(self.batch_size * [[self.height, self.width, self.channels]], dtype=tf.int32)

    self.model.provide_groundtruth(groundtruth_boxes_list=groundtruth_boxes_list,
                                                         groundtruth_classes_list=groundtruth_classes_list)

    with tf.GradientTape() as tape:
      preprocessed_images = self.model.preprocess(image_tensors)[0]
      prediction_dict = self.model.predict(preprocessed_images, shapes)

      losses_dict = self.model.loss(prediction_dict, shapes)
      total_loss = losses_dict['Loss/localization_loss'] + losses_dict['Loss/classification_loss']
      gradients = tape.gradient(total_loss, self.vars_to_fine_tune)
      self.optimizer.apply_gradients(zip(gradients, self.vars_to_fine_tune))
    return total_loss

But I am struggeling to see how I can test the model after each epoch or N steps to see the accuracy? Since the is_training parameter is set to True, I guess I have to set it to False in some way and do predictions outside the tf.GradientTape loop? Or is there any test fuction built into the model that can be used?
Thanks for any help!

Context:
Here you can find a complete example of a custom train + evaluation loop:

      keras.io

Keras documentation: Writing a training loop from scratch 7


Unable to Access a URL Using Tensorflow_hub

Question:
I am new to tensorflow and I am trying to run a research project. It seems like tensorflow_hub cannot access the url “TensorFlow Hub 2”
The research project is running on python 2.7 and tensorflow 1.8 environment. To run tensorflow_hub on this environment, I downloaded tensorfloe_hub == 0.4.0 version.
This line of code get the error

self.lm_hub = hub.Module(config[“lm_path”].encode(“utf-8”), trainable=False)

This is the error message.

Using tensorflow hub: TensorFlow Hub 2
Traceback (most recent call last):
File “decoder.py”, line 37, in
data = LSGNData(config)
File “/home/xuan/Desktop/linux_research/lsgn-master/lsgn_data.py”, line 51, in init
self.lm_hub = hub.Module(config[“lm_path”].encode(“utf-8”), trainable=False)
File “/home/xuan/anaconda3/envs/py27/lib/python2.7/site-packages/tensorflow_hub/module.py”, line 147, in init
self._spec = as_module_spec(spec)
File “/home/xuan/anaconda3/envs/py27/lib/python2.7/site-packages/tensorflow_hub/module.py”, line 36, in as_module_spec
return load_module_spec(spec)
File “/home/xuan/anaconda3/envs/py27/lib/python2.7/site-packages/tensorflow_hub/module.py”, line 60, in load_module_spec
path = registry.resolver(path)
File “/home/xuan/anaconda3/envs/py27/lib/python2.7/site-packages/tensorflow_hub/registry.py”, line 42, in call
return impl(*args, **kwargs)
File “/home/xuan/anaconda3/envs/py27/lib/python2.7/site-packages/tensorflow_hub/compressed_module_resolver.py”, line 103, in call
self._lock_file_timeout_sec())
File “/home/xuan/anaconda3/envs/py27/lib/python2.7/site-packages/tensorflow_hub/resolver.py”, line 400, in atomic_download
download_fn(handle, tmp_dir)
File “/home/xuan/anaconda3/envs/py27/lib/python2.7/site-packages/tensorflow_hub/compressed_module_resolver.py”, line 98, in download
response = url_opener.open(request)
File “/home/xuan/anaconda3/envs/py27/lib/python2.7/urllib2.py”, line 429, in open
response = self._open(req, data)
File “/home/xuan/anaconda3/envs/py27/lib/python2.7/urllib2.py”, line 447, in _open
‘_open’, req)
File “/home/xuan/anaconda3/envs/py27/lib/python2.7/urllib2.py”, line 407, in _call_chain
result = func(*args)
File “/home/xuan/anaconda3/envs/py27/lib/python2.7/urllib2.py”, line 1241, in https_open
context=self._context)
File “/home/xuan/anaconda3/envs/py27/lib/python2.7/urllib2.py”, line 1198, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 110] Connection timed out>

Could anyone explain what is going on and how to fix this problem, please? Thank you very much.

Context:
HI,
I think for the old TF (1.x) you should use TFHub version 0.11.0 (guide 2).
One other thing I’d suggest is to move to a newer Python and TF version. you might get many issues that were already solved in newer versions.