Categories
Misc

TensorFlow 1.15 C++ API Documentation

Hello,

I train TensorFlow models using the Python version but I need them to run using the C++ api. I had previously compiled libtensorflow.so version 1.11 and used the models successfully, however, when trying to use the same program with the 1.15 version it fails with an segmentation fault. I assume the way a model loads changed between 1.11 and 1.15 using the C++ api, however, I cannot for the life of me find documentation on the C++ API version 1.15 since the official site always redirects to version 2.8.

Could anyone please point me to the v1.15 documentation of the C++ api, please?

submitted by /u/quinseptopol
[visit reddit] [comments]

Categories
Misc

TinyML Monitoring Air Quality an 8-bit Microcontroller

TinyML Monitoring Air Quality an 8-bit Microcontroller

I’d like to share my experiment on how to easily create your own tiny machine learning model and run inferences on a microcontroller to detect the concentration of various gases. I will illustrate the whole process with my example of detecting the concentration of benzene (С6H6(GT)) based on the concentration of other recorded compounds.

Things I used in this project: Arduino Mega 2560, Neuton Tiny ML software

To my mind, such simple solutions may contribute to improving the air pollution problem which now causes serious concerns. In fact, the World Health Organization estimates that over seven million people die prematurely each year from diseases caused by air pollution. Can you imagine that?

As such, more and more organizations, responsible for monitoring emissions, need to have effective tools at their disposal to monitor the air quality in a timely way, and TinyML solutions seem to be the best technology for that. They are quite low-energy and cheap to produce, as well as they don’t require a permanent Internet connection. I believe these factors will promote the mass implementation of TinyML as a great opportunity to create AI-based devices and successfully solve various challenges.

Therefore, in my experiment, I take the most primitive 8-bit MCU to show that even such a device today can have ML models in it.

Dataset description:

My dataset contained 5875 rows of hourly averaged responses from an array of oxide chemical sensors that were located on the field in a polluted area in Italy, at road level. Hourly averaged concentrations for CO, Non-Metanic Hydrocarbons, Benzene, Total Nitrogen Oxides (NOx), and Nitrogen Dioxide (NO2) were provided.

It is a regression problem.

Target metric – MAE (Mean Absolute Error). Target – C6H6(GT).

Attribute Information:RH – Relative Humidity

AH – Absolute Humidity

T – Temperature in °C;

PT08.S3(NOx) – Tungsten oxide. Hourly averaged sensor response (nominally NOx targeted);

PT08.S4(NO2) – Tungsten oxide. Hourly averaged sensor response (nominally NO2 targeted);

PT08.S5(O3) – Indium oxide. Hourly averaged sensor response (nominally O3 targeted);

PT08.S1(CO) – (Tin oxide) hourly averaged sensor response (nominally CO targeted);

CO(GT) – True hourly averaged concentration CO in mg/m^3 (reference analyzer);

PT08.S2(NMHC) – Titania. hourly averaged sensor response (nominally NMHC targeted);

You can see more details and download the dataset here: ​​https://archive.ics.uci.edu/ml/datasets/air+qualityProcedure:

Step 1: Model Training

The model was created and trained with a free tool, Neuton TinyML, as I needed a super compact model that would fit into a tiny microcontroller with 8-bit precision. I tried to make such a model with the help of TensorFlow before, but it was too large to run operations on 8 bit.

To train the model, I converted the dataset into a CSV file, uploaded it to the platform, and selected the column that should be trained to make predictions.

https://preview.redd.it/yhbwvcy2qjk81.png?width=1899&format=png&auto=webp&s=49d568a9aea5bb64885c5e7a3d1170acb4209bc2

https://preview.redd.it/lwhmfey3qjk81.png?width=1901&format=png&auto=webp&s=04f7e50945f153e7f4db600f93015c3c8ec9fb48

The trained model had the following characteristics:
The model turned out to be super compact, having only 38 coefficients and 0.234 KB in size!

https://preview.redd.it/gkizygs5qjk81.png?width=1900&format=png&auto=webp&s=1a689e0fb926995fe223e7591ac64cb9c428abe7

Additionally, I created models with TF and TF Lite and measured metrics on the same dataset. The comparison speaks louder than words. Also, as I said above, TF models still cannot run operations on 8 bits, but it was interesting for me to use just such a primitive device.

https://preview.redd.it/y7l0ibr8qjk81.png?width=1497&format=png&auto=webp&s=8580bedc3436d719bd2246249b1af4e9ba482e44

Step 2: Embedding into a Microcontroller

Upon completion of training, I downloaded the archive which contained all the necessary files, including meta-information about the model in two formats (binary, and HEX), calculator, Neuton library, and the implementation file.

https://preview.redd.it/ftuagzt9qjk81.png?width=1900&format=png&auto=webp&s=679c238c137f9e1418fb5c58ef7a72a1d5c20118

Since I couldn’t run the experiment in field conditions with real gases, I developed a simple protocol to stream data from a computer.

Step 3: Running Inference on the Microcontroller

I connected a microcontroller on which the prediction was performed to a computer via a serial port, so signals were received in a binary format.

The microcontroller was programmed to turn on the red LED if the concentration of benzene was exceeded, and the green LED – if the concentration was within permitted limits. Check out the videos below to see how it worked.

https://reddit.com/link/t3c29p/video/l1j4qk1ypjk81/player

In this case, the concentration of benzene is within reasonable bounds (<15 mg/m3).

https://reddit.com/link/t3c29p/video/wm4agr7zpjk81/player

In this case, the concentration of benzene exceeds the limits (>15 mg/m3).

Conclusion

My example vividly illustrates how everyone can easily use the TinyML approach to create compact but smart devices, even with 8-bit precision. I’m convinced that the low production costs and high efficiency of TinyML open up enormous opportunities for its worldwide implementation.

Due to the absence of the need to involve technical specialists, in this particular case, even non-data scientists can rapidly build super compact models and locate smart AI-driven devices throughout the area to monitor air quality in real-time. To my mind, it’s really inspiring that such small solutions can help us improve the environmental situation on a global scale!

submitted by /u/literallair
[visit reddit] [comments]

Categories
Misc

[tf.js] Is there an equivalent to Keras’ Resizing layer?

I’m using tensorflow.js and I need a layer that can take in an image and output the image resized at a new resolution (bilinear filtering is fine.) I can’t find one in the tf.js API so I’m not sure what I can use. I need to make sure the model can still be serialized to disk, so I think writing a custom layer class might be off the table.

Any help would be appreciated.

submitted by /u/SaltyKoopa
[visit reddit] [comments]

Categories
Misc

Tensorflow not working in Jupyter Notebook (Anaconda)

I did this in Linux Mint, a Ubuntu variant, and I did do pip install tensorflow and all of that, granted when I try pip3 install tensorflow, I get a wall of red text.

Relevant code is:

import tensorflow as tf

from tensorflow import keras

from tensorflow.keras import layers

#Defining the model using default linear activation function

model=keras.Sequential()

model.add(layers.Dense(14))

model.add(layers.Dense(4))

model.add(layers.Dense(1))

2022-02-27 11:34:48.204164: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set 2022-02-27 11:34:48.204436: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library ‘libcuda.so.1’; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory 2022-02-27 11:34:48.204446: W tensorflow/stream_executor/cuda/cuda_driver.cc:326] failed call to cuInit: UNKNOWN ERROR (303) 2022-02-27 11:34:48.204464: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (term-IdeaPad-Flex): /proc/driver/nvidia/version does not exist 2022-02-27 11:34:48.204624: 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: SSE4.1 SSE4.2 AVX AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2022-02-27 11:34:48.204886: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set

I have an all AMD laptop, but I don’t see how you need NVIDIA when I see people using it in virtual machines. If you know of a way for me to fix this, or do something where I can upload to a different site, and have that work, let me know.

submitted by /u/Term_Grecos
[visit reddit] [comments]

Categories
Misc

Is tensorflow a workable solution for my side project?

Is tensorflow a workable solution for my side project?

Hello,

I am in the process of learning TensorFlow and I am wondering if TF is a workable solution for what I am trying to achieve. My side project is chess website where users can come submit their chess ratings, and then the website uses their data to compare ratings between different chess websites and orgs. My data set currently has around 7500 rows and looks like this:

7500 rows that look about like this

My backend is a Python API that is hosted on Heroku. What I would like to achieve is that once a player enters in their ratings, every rating they leave empty, I use machine learning/TensorFlow to predict each null value for that player? Is that doable with TF in backend hosted on Heroku?

Also, if anyone has any tips to lead me in the right direction, they are most welcome. I should also note that I suspect this might not be the most appropriate use of TF, or that TF might not be the best solution, but I am using this side project go grow and demonstrate skills I take interest in .

submitted by /u/DavidDoesChess
[visit reddit] [comments]

Categories
Misc

Issue in train step of custom keras model when passing data from a generator

I found a very similar issue to the one I am having on stack overflow here, but I’m posting here because no one figured it out. That post pretty much explains the issue I am having, but I am using an ImageDataGenerator instead. I cant seem to be able to get it to work within the train_step of a custom keras model. Any help is appreciated

submitted by /u/proxygonn
[visit reddit] [comments]

Categories
Misc

Closest pair of points problem optimized with tensorflow?

I am a novice when it comes to tensorflow and AI.

I wrote a solution to the problem first with numpy, then numba optimized. When it comes to tensors, I have no idea how to even start the optimization. Are there some easy to follow tutorials out there? How do I even tell tensorflow the rules and goal of the optimization?

https://github.com/XeonPhobia/Pixel-replacement-algorithm-based-on-RMSE/blob/main/test.py

submitted by /u/Xeonfobia
[visit reddit] [comments]

Categories
Misc

Predict function takes super long

Hey (obligatory i am pretty noob). I’m training a neural network with Tensorflow (deuh) and during training the network takes about 300 micro seconds per sample. This is with dropout and layer normalization and back propagation of course and with 4 threads. During predictions however I can only predict one sample at a time (due to external needs) I would expect this to take about 1 ms or even less but when actually timing it I get more like 12ms. Are there any ways I can speed up this behavior how much can a less complex neural network bring me?

submitted by /u/davy123457
[visit reddit] [comments]

Categories
Misc

Variational Autoencoder for CIFAR-10

You can read about here implemented in TensorFlow 2.8, trained in tf.GradientTape() API.

submitted by /u/grid_world
[visit reddit] [comments]

Categories
Misc

Can I use tensorflow to extend a 3D array in a direction of my choice?

This 3D array (https://imgur.com/a/BCuCJNM) is a cross-section of a forest. I would like to predict additional forest slices moving in the x or y direction. I found this tutorial online, but this tutorial is for a 1D data set (https://www.codespeedy.com/predict-next-sequence-using-deep-learning-in-python/).

submitted by /u/yhl3051
[visit reddit] [comments]