Platform node has already been set. Overwriting the platform with…cpu backend was already registered

Question:
This is a sort of a three part question.   Trying to convert my computer vision application with tfjs-node to use serverless off-line, it’s working.  However, each time the function is invoked, it’s printing out
Platform node has already been set. Overwriting the platform with [object Object].
cpu backend was already registered. Reusing existing backend factory.
The kernel '_FusedMatMul' for backend 'cpu' is already registered
The kernel 'Abs' for backend 'cpu' is already registered
The kernel 'Acos' for backend 'cpu' is already registered
The kernel 'Acosh' for backend 'cpu' is already registered
...
The kernel 'Unpack' for backend 'tensorflow' is already registered
The kernel 'UnsortedSegmentSum' for backend 'tensorflow' is already registered
The kernel 'ZerosLike' for backend 'tensorflow' is already registered
tensorflow backend was already registered. Reusing existing backend factory.

Which is fine,
Q1:
If it thinks it’s already loaded, is there a way to check and avoid printing them out every time?
Q2:
If it thinks tfjs-node is loaded, is there a way to check if the model has been loaded in subsequent function invocation to avoid having to call loadSavedModel again?
Q3:
If needs to load in a different model with loadSavedModel, is there a way to flush the model in memory before calling loadSavedModel?
Thank you

Context:
This is not about model being loaded again, its about tfjs itself being loaded twice.
For example, if you’re loading both @tensorflow/tfjs and @tensorflow/tfjs-node, then you get this since tfjs-node already includes tfjs.


Running out of GPU memory with just 3 samples of 640x480x3 images

Question:
Hi, I’m training a model with model.fitDataset. The input dimensions are [480, 640, 3] with just 4 outputs of size [1, 4] and a batch size of 3.
Before the first onBatchEnd is called, I’m getting a High memory usage in GPU, most likely due to a memory leak warning, but the numTensors after every yield of the generator function is just ~38, the same after each onBatchEnd, so I don’t think I have a leak due to undisposed tensors.
While debugging the internals of TFjs I noticed that in acquireTexture, the numBytesInGPU goes above 2.2G, which is triggering the warning.
Is this normal behavior for that image size? It means I cannot increase my batchSize because I run out of memory with anything greater than 3.
Is there anything I can do to reduce the GPU memory usage?
Thanks!

Context: @Jason might be able to share some insights on this


Question:
Hi all!
I’ve followed this tutorial given on TensorFlow’s website about image captioning, and I’ve extended the model to Transformers. Now I want to deploy the model on a web application, but I’m finding difficulties in that. Can anyone guide me how to do this? It’ll be a great help. Thanks.

Context: Do you want to run the model inside the browser (TF.js) or with a client/server approach?


How to concatenate and shuffle two tensorflow dataset with 10000 records each without running out of memory (11GB)

Question:
Hey,
I’m relatively new to tensorflow so please excuse me if this is a
beginner question:D
Here is what I’m trying to do:
I have 2 separate Datasets:

melanoma_ds: contains 10000 true positive cases (Tensorflow dataset)
no_melanoma_ds: contains 10000 true negative cases (Tensorflow dataset)

I would like to concatenate these two datasets and do a shuffle afterwards.
train_ds = no_melanoma_ds.concatenate(melanoma_ds)
My  problem is the shuffle.
I want to have a well shuffled train dataset so I tried to use:
train_ds = train_ds.shuffle(20000)
I’m using google colab and it seems like I ran out of graphic card memory (limit of 11GB).
 → colab session crashes
So I tried to pick smaller batches (5000 instead of 20000) from my two datasets no_melanoma_ds
and melanoma_ds shuffle them with a buffer_size of only 5000 and  concatenate all of them afterwards:
def memory_efficient_shuffle(melanoma_ds=melanoma_ds, no_melanoma_portion=no_melanoma_portion):
  shuffle_rounds = 4
  tmp_start = 0
  batch_each_class = 2500
  final_shuffle_ds = None

  for i in range(shuffle_rounds):
    tmp_start = batch_each_class * i
    tmp_melanoma_ds = melanoma_ds.skip(tmp_start).take(batch_each_class)
    tmp_no_melanoma_ds = no_melanoma_portion.skip(tmp_start).take(batch_each_class)
    both_portions_ds = tmp_melanoma_ds.concatenate(tmp_no_melanoma_ds)
    shuffled_portion_ds = both_portions_ds.shuffle(5000)

    final_shuffled_ds = shuffled_portion_ds if final_shuffle_ds == None else final_shuffle_ds.concatenate(shuffled_portion_ds)
  return final_shuffled_ds

This actually works and the session does not crash…
But if I try to pick the first element of the shuffled dataset it takes too much time and i don’t know if the program will ever terminate.
final_shuffled_ds = memory_efficient_shuffle()
image, label = next(iter(final_shuffled_ds))

I bet I made a lot of mistakes during the whole process:D
I really would like to know how would you approach this?

Context: try using float32 data units instead of float64 this could save your space issue.


Question:
The example for 8-bit quantization aware training runs perfectly. I am looking for 4-bit quantization. Unfortunately, I could not find it in the documentation. Please point me in the right direction.
Thanks

Context:
You can find an example of a 4-bit dense layer at:

      colab.research.google.com

Google Colaboratory 5


How to take an H5 file and run and use it for image recognition

Question: I have an .h5 file but and I want to be able to use and run it for image recognition. I will also eventually have to import it and be able to use it on an andrioid device, so if anyone knows how to do it, help would be appreciated

Context:
Hi @Ian_Shi
Take a look how to reload a model when you have a .h5 file here 8.
For android implementation you have to convert it to .tflite file and use it. Check the documentation for conversion 2 and usage 1.
Best


Python crashes when I run tf.random.normal([1000, 1000]) in TensorFlow 2

Question:
When I run the following code in python:
import tensorflow as tf
import os
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
tf.random.normal([1000, 1000])

the last line `tf.random.normal([1000, 1000])’ crashes Python. This is the screenshot:
please see the screenshot image. 3
I’m sorry I don’t know how to handle the triple > which mess up the formatting so I have to use screenshot image. As can be seen from the output, the error message is

F tensorflow/core/platform/default/env.cc:73] Check failed: ret == 0
(11 vs. 0)Thread tf_numa_-1_Eigen creation via pthread_create()
failed.

Since the sys admin is very disagreeable, I have to figure out what the problem is myself. But I really don’t know what the cause of the crash could be. I had thought it is because the RAM is too small, but this thread 2 says TF2 can start with a limited RAM size. I’m at my wits end so I ask here for help. Following is the configuration of the machine:

Remote Linux with core version 5.8.0. I am not a super user.
Python 3.8.6
CUDA Version: 11.1
GPU is RTX 3090 with driver version 455.23.05
CPU: Intel Core i9-10900K
TensorFlow version: 2.6.0
System imposed RAM quota: 4GB
System imposed number of threads: 512198
System imposed RLIMIT_NPROC value: 300

If you need other information related to this error, please let me know. Thank you for helping me troubleshoot this problem.

Context:
Do you have the same problem with:

      TensorFlow

tf.config.experimental.set_memory_growth  |  TensorFlow Core v2.6.0 7

  Set if memory growth should be enabled for a PhysicalDevice.


How does one do similarity comparison of neural networks in tensorflow or keras?

Question:
I wanted to run pwcca, svcca, CKA, OP etc in tensorflow to analyze the similarity of neural networks. What is the recommended api/interface for tensorflow for this?
e.g./context:

Raghu et al. NIPS2017 SVCCA
Marcos et al. NeurIPS2018 PWCCA
Kornblith et al. ICML2019 Linear CKA

and

      github.com

GitHub - moskomule/anatome: Ἀνατομή is a PyTorch library to analyze... 2

  Ἀνατομή is a PyTorch library to analyze representation of neural networks - GitHub - moskomule/anatome: Ἀνατομή is a PyTorch library to analyze representation of neural networks

Context: crossposted: https://www.reddit.com/r/learnmachinelearning/comments/qapw3a/how_does_one_do_similarity_comparison_of_neural/ 6


Question:
I wanted a Coral for my PC, so figured I’d buy the mini PCIe card and get an adapter for installation. But it seems like nobody supports half-height cards. Now I’ve got this Coral board with no way to use it.
Does anyone know where I can get a PCIe adapter that supports Google’s difficult half-height design.
Also, the dual TPU design on the M.2 card is a great idea. But guess what, it’s just as infuriating trying to find E-key adapters! Who at Google thought hey, let’s build these things but also let it be really difficult to support plugging them into PC’s!?

Context:
Hi Brym Stone,
Thanks for brought up the issue here!  A few comments and suggestions to answer your questions…

The Coral mPCIe module should be able to just plug into any mPCIe slot, so I think the issue isn’t the physical half-height for the card but rather the mother board supports the standard mPCIe interface.  The module has been mostly used by industrial PCs and controllers, and we have not received any complaints about the compatibility or lack of support on those platforms. That being said, there might be some issues with the personal computers for home use, and that is also likely highly dependent on the vendor or brand of your PC.  To resolved this specific issue for you, please contact our customer support team directly at coral-support@google.com, and our filed engineering team can help you look at the possible solutions.  Please provide the brand and model number of your PC or the motherboard, and whatever the system configuration you have.

The dual-EdgeTPU M.2 module was originally designed for one of the special business product that required dual PCIe buses, and unfortunately, vast majority of the system board vendors have not implemented this standard so far. So this is really not we built something to be difficult to use, but due to the slow or lack of the adoption by host board vendors to support the dual PCIe bus standard, which isn’t something we can control.  It’s possible for making a dual-EdgeTPU module to work with the current single-PCIe bus host boards, by creating a M.2 module that uses an extra switch chip for the dual Edge TPUs, and we have discussed this with some host board vendors, and they are looking into to offer a product with this solution. But until that is done, most of the current host boards will not work with the dual-EdgeTPU M.2 module.

That being said, there are a few industry controller vendors who have products that supports the dual PICe buses. For example, Nexcom has a NDiS B537 box that supports the Coral module.
In any case, for you to use home PC (or laptop) with a Coral module, one easy alternative is to use the Coral USB module, as this module has the on-bard chip that enables USB3 interface speed if your PC supports USB3, which will get you similar performance to the PCIe bus.
But please feel free to contact our support using the email above if you wish to discuss further and explore more solution options in using the Coral products with your PC.  Thank you for your interests in using Coral!
Bill Luan
Coral Team


Question: Hi all, I am a beginner here and want to know how to start contributing to this community . For now , I want to start contributing to docs so can anyone please guide me for this ?

Context:
Welcome,
for the Tensorflow core you can take a look at:

      TensorFlow

Contribute to the TensorFlow documentation 25


Classifynig dicom images for lung cancer

Question:
Hello all,
I want to write a code to find lung cancer for me. To illustrate, if I have 100 MRI pictures, the code should seperates them as those which have the lung cancer and which have not. If there is a similir code or example for it, it would be helpful for me.

Context:
I think that your dataset is too small but you can find a starting tutorial at:

      Medium – 5 Jun 20

Classification of Brain MRI as Tumor/Non Tumor 2

  Learn to train and apply a simple CNN to differentiate between an MRI with a Tumor and an MRI without one.

    Reading time: 8 min read

If you want to explore segmentation I suggest to take a look at the annual BraTS challenge.
Here you can find the announce of some of the top results in the 2021 challenge:

      NVIDIA Developer Blog – 30 Sep 21

NVIDIA Data Scientists Take Top Spots in MICCAI 2021 Brain Tumor Segmentation... 2

  NVIDIA data scientists took three of the top spots in a brain tumor segmentation challenge validation phase at the prestigious MICCAI 2021.


Unable to use multi GPU with tensorflow recommender

Question:
I want to train recommender model by multi GPUs.
I used this tutorial code " [

Recommending movies: retrieval with distribution strategy
](Recommending movies: retrieval with distribution strategy)"
,
but my 2nd GPU’s utilization is around 1~2%.(1st GPU’s utilization is around 40%)

How can I get the second GPU to work properly?

Context:
Did you skip this section?

      TensorFlow

Recommending movies: retrieval with distribution strategy 5


Tensorflow Text Classification with BERT

Question:
Hi, I have a question about the documentation found on tensorflow.org involving BERT.
There is one tutorial called “Classify Text with BERT” Classify text with BERT  |  Text  |  TensorFlow 3
Here is another - “Fine-tuning a BERT model”

      TensorFlow

Fine-tuning a BERT model  |  Text  |  TensorFlow 6

I was wondering what the difference between the two is when it comes to preprocessing data. Specifically, in the “Classify Text with BERT” tutorial, preprocessing the data is just using a preprocessing model provided by Tensorflow Hub. On the other hand, “Fine-tuning a BERT model” uses python code to tokenize and encode the data and stuff; it just seems a lot more complicated than using the preprocessing model provided.
So basically, I was wondering if there is an actual difference between these two preprocessing methods, and there is a reason for why one uses a model and the other actually implements python code?

Context:
Hi William,
The differences in summary what you notices, the use of preprocess models.
If you can avoid using all the Python code to do the BERT preprocessing you should! that will make your life much easier. Both when training the model and when serving where you’ll need to have the preprocessing code also available.
Why there’s a colab with the Python raw code then?
Because it will show you everything that is happening inside the preprocess model if you want to have a deeper understand. The other reason is, if you don’t have a preprocess model available, you will know what to do.


Question:
My model takes one input and gives two outputs , I’m passing it in a dictionary:
train_dataset = tf.data.Dataset.from_tensor_slices(
    (
        {"input_1": atr},
        {"ed": wtr, "sd": wbtr},
    )
)
train_dataset = train_dataset.batch(100).repeat(3)

Shape of all the three arrays atr , wtr and wbtr is (7838, 512, 1).
This is my model:
import tensorflow as tf
import tensorflow_addons as tfa
from tensorflow.keras import Input, Model
input1 = tf.keras.layers.Input(shape=(None,1),name="input_1")
x = tf.keras.layers.Conv1D(filters=16, kernel_size=3, strides=1, padding="causal", activation="relu",input_shape=[None,1])(input1)
x = tf.keras.layers.Bidirectional(tf.keras.layers.GRU(128, activation="tanh", return_sequences=True))(x)
x = tf.keras.layers.Bidirectional(tf.keras.layers.GRU(256, activation="tanh", return_sequences=True))(x)
x = tf.keras.layers.Dense(128, activation="tanh")(x)
o1 = tf.keras.layers.Dense(1, activation="linear",name="ed")(x)
o2 = tf.keras.layers.Dense(1, activation="sigmoid",name="sd")(x)

model = Model(inputs=[input1], outputs=[o1, o2])

model.compile(loss={'ed': 'mean_squared_error',
                    'sd': 'binary_crossentropy'},
              loss_weights={'ed':0.4,
                            'sd':0.6},
              optimizer='adam',
              metrics={'ed': tf.keras.metrics.MeanAbsoluteError(name="mean_absolute_error", dtype=None),
                       'sd': tfa.metrics.F1Score(name="f1_score",num_classes=2, threshold=0.5)})

Here is the model summary:
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to
==================================================================================================
input_1 (InputLayer)            [(None, None, 1)]    0
__________________________________________________________________________________________________
conv1d_18 (Conv1D)              (None, None, 16)     64          input_1[0][0]
__________________________________________________________________________________________________
bidirectional_33 (Bidirectional (None, None, 256)    112128      conv1d_18[0][0]
__________________________________________________________________________________________________
bidirectional_34 (Bidirectional (None, None, 512)    789504      bidirectional_33[0][0]
__________________________________________________________________________________________________
dense_17 (Dense)                (None, None, 128)    65664       bidirectional_34[0][0]
__________________________________________________________________________________________________
ed(Dense)                      (None, None, 1)      129         dense_17[0][0]
__________________________________________________________________________________________________
sd (Dense)                      (None, None, 1)      129         dense_17[0][0]
==================================================================================================
Total params: 967,618
Trainable params: 967,618
Non-trainable params: 0
__________________________

Finally my model.fit() method:
history = model.fit(train_dataset,epochs=3,verbose=1,steps_per_epoch= 78)

Here is the error:
    InvalidArgumentError: Cannot update variable with shape [2] using a Tensor with shape [512,1], shapes must be equal. [Op:AssignAddVariableOp]

I don’t where I’m going wrong , pls help.

Context:
Hi,Guitar_George!
I applied
‘sd’: tfa.metrics.F1Score(name=“f1_score”, num_classes=2, threshold=0.5, average=“micro”)})
and in this case there was no error.


Creating my tensorflow dataset from multiple binary files

Question:
Hello,
I am fairly new to tensorflow, python and machine learning in general but have made a lot of progress in the last few months. I have a CNN that I have used on png images, but I would like to use that CNN with another dataset. Each ‘image’ in this new dataset includes 7 separate matrices stored in 7 different binary format files. I want each matrix to be a channel (shape = x, x, 7). The mask is a single matrix in a single binary formatted file. I am not sure how to preprocesses this type of data to prepare it for the model. Any help, guidance or links to helpful sources is greatly appreciated.
Best,
Kevin

Context:
Have you tried to write your decode function like in:

      TensorFlow

tf.data.TFRecordDataset  |  TensorFlow Core v2.6.0 8

  A Dataset comprising records from one or more TFRecord files.


[Q]: Resources for Instance Segmentation in TF.K

Question:
Can you share some resources (official and non-official but trusted sources) for

semantic,
instance, and
panoptic segmentation

which is done by pure TensorFlow or TensorFlow.Keras (preferred)?

Context:
You can find some of the official Garden models at:
Panoptic:

      github.com

models/official/vision/beta/projects/panoptic_maskrcnn at master ·... 4

  master/official/vision/beta/projects/panoptic_maskrcnn

  Models and examples built with TensorFlow. Contribute to tensorflow/models development by creating an account on GitHub.

Instance:

      github.com

models/official/vision/beta/projects/deepmac_maskrcnn at master ·... 2

  master/official/vision/beta/projects/deepmac_maskrcnn

  Models and examples built with TensorFlow. Contribute to tensorflow/models development by creating an account on GitHub.

Some TFHUB models:
https://tfhub.dev/s?module-type=image-segmentation
Some community garden models:

      github.com

models/community at master · tensorflow/models - Segmentation

  master/community

  Models and examples built with TensorFlow. Contribute to tensorflow/models development by creating an account on GitHub.

And also some keras community and Tensorflow example/tutorials/notebooks at:

      keras.io

Keras documentation: Computer Vision

      TensorFlow

Image segmentation  |  TensorFlow Core

      TensorFlow

Segmentation  |  TensorFlow Lite 1


Question:
Feature

The ability to create tf.Tensors that hold custom objects.

Motivation

I am currently working on deep learning models using data encrypted with homomorphic encryption. This data is stored in a custom Python class with operator overloading. Right now, this functionality works with neural networks developed from scratch using NumPy, but having access to TensorFlow’s suite of deep learning capabilities would make this work much more robust and scalable to various network architectures.

Pitch

NumPy’s ndarray is able to hold custom Python objects and call overloaded NumPy functions, allowing us to work with the encrypted data in various ways. Something similar with TensorFlow’s robust deep learning capabilities would be very useful.

Context:
As I know I don’t think is possibile now. Is your the same case as?

      github.com/tensorflow/tensorflow

      TensorArray support dtype of Custom defined  class object? 7

        opened

        Oct 15, 2021

          joan126

        type:others

    This template is for miscellaneous issues not covered by the other issue categor…ies.

For questions on how to work with TensorFlow, or support for problems that are
not verified bugs in TensorFlow, please go to
[Discourse](https://discuss.tensorflow.org/).

If you are reporting a vulnerability, please use the [dedicated reporting process](https://github.com/tensorflow/tensorflow/blob/master/SECURITY.md).

For high-level discussions about TensorFlow, please post to discuss@tensorflow.org, for questions about the development or internal workings of TensorFlow, or if you would like to know how to contribute to TensorFlow, please post to developers@tensorflow.org.

I think you could find a short analisys in this ttf-encrypted TF big tensor library ticket:

      github.com/tf-encrypted/tf-big

      Extend support to tensors 3

        opened

        Jul 2, 2019

          mortendahl

    Right now we only support matrices; using eg https://eigen.tuxfamily.org/dox-dev…el/unsupported/eigen_tensors.html we might support more general tensors as well

Also, more in general, have you tried to see what was their approach in:

      github.com

GitHub - tf-encrypted/tf-encrypted: A Framework for Encrypted Machine Learning... 4

  A Framework for Encrypted Machine Learning in TensorFlow - GitHub - tf-encrypted/tf-encrypted: A Framework for Encrypted Machine Learning in TensorFlow

      github.com

GitHub - tf-encrypted/tf-seal: Bridge between TensorFlow and the Microsoft SEAL... 1

  Bridge between TensorFlow and the Microsoft SEAL homomorphic encryption library - GitHub - tf-encrypted/tf-seal: Bridge between TensorFlow and the Microsoft SEAL homomorphic encryption library

      github.com

GitHub - tf-encrypted/tf-pjc: Bridge between TensorFlow and Google's Private... 1

  Bridge between TensorFlow and Google's Private Join and Compute library - GitHub - tf-encrypted/tf-pjc: Bridge between TensorFlow and Google's Private Join and Compute library


How is PyTorch different from TensorFlow?

Question: Hi Please give me reply?

Context:
I think this post might help you:

      Medium – 8 Jun 21

Pytorch vs Tensorflow 2021 7

  Tensorflow/Keras & Pytorch are by far the 2 most popular major machine learning libraries. Tensorflow is maintained and released by Google while Pytorch is maintained and released by Facebook. In…

    Reading time: 5 min read

If you ask me for my personal opinion I find Tensorflow more convenient in the industry (prototyping, deployment and scalability is easier) and PyTorch more handy in research (its more pythonic and it is easier to implement complex stuff). I encourage you to learn both !


Tensorflow warning and information prints

Question: Hello, I am using tf in my backend application and once i run the .py file with tf import without even use it . It took time to print warnings snd information of tf libraries trace and then it continue the .py code process. What should i have to do to stop tf from make this trace it’s really increase my code response time. One of the warrning it says that i don’t have tf gpu libraries even that i am not using tf functions just what i did is to import it.

Context:
You can set your log level before importing TF with:
os.environ['TF_CPP_MIN_LOG_LEVEL']


Question:
Hi everyone,
I’m fine-tunning a transformer model (BERT) using the procedure described here (Fine-tuning a pretrained model — transformers 4.11.3 documentation 3) using keras/TensorFlow.
The model was running without any problem until yesterday, when it started to throw this error: AttributeError: ‘tensorflow.python.framework.ops.EagerTensor’ object has no attribute ‘to_tensor’.

image889×410 141 KB

I’m still able to run the model in a local TensorFlow configuration that I have in my Apple M1 laptop, but I can’t run it in Google Colab/ Amazon SageMaker, etc.  The model was running just fine in Google Colab until yesterday when it started trowing the error.
I wonder what can be happening. I really appreciate if someone could shed some light.
Thanks,
Isabel
#help_request
#keras

Context:
Sorry for the issue.
I don’t know exactly what’s wrong but to help debug the issue it would be nice to find out what object is that and find the version of the package that it’s defined. I’d guess there was a package update on the cloud envs (colab and sagemaker) and not in your local env. That would explain why it works locally and not on the cloud


Custom layer using numpy.inf conflicts with tensorflow lite interpreter

Question:
Hello!
I have custom padding layer that fills the inputs/activations of my model with constant_values = -numpy.inf instead of 0 to then act with maxpooling2d (basically compare between -inf and the activation value). Once converted the tflite model to int8 (full-integer post-training quantization) and load the model with the tflite interpreter I get the following output
RuntimeError: tensorflow/lite/kernels/pad.cc:118 op_context.input->type != op_context.constant_values->type (INT8 != FLOAT32)Node number 3 (PADV2) failed to prepare.

I guess this problem is due to the fact that padding cannot fill with -inf an input that is int8, I would appreciate if you can give me some advice regarding this, how can I fill an int8 input to compare its values with -inf in a quantized way
Thank you in advance
==== Status 23.09.21 ====
After changing the constant values of -numpy.inf in the custom padding layer in favor of x.dtype.min:
    def call(self, x):
        paddings = [[0, 0]] + self._explicit_pad + [[0, 0]]
        return tf.pad(x, paddings=paddings, mode='CONSTANT',
                      constant_values= 0 if self.layer_type == 'conv' else x.dtype.min)

for pooling layers the tflite quantized model is still comparing and int8 input with a float → x.dtype.min and when calling tf.lite.Interpreter.allocate_tensors():

Context: Adding @tei.jeong @Thai_Nguyen for the visibility.


Question:
Hey Community, I hope you’re doing fine.
I’m trying to load a local csv file, which contains my training data, but i couldn’t figure out how to do it.
the csv file contain the following columns:
TweetId, TweetText, Label
they are all string data except the Tweet id!
can you help me please.

Context:
Hi! Here is a tutorial on loading data from files of various formats: tf.data: Build TensorFlow input pipelines  |  TensorFlow Core 7
In your case you should just read the local file using pandas.read_csv() and then process it as shown in the tutorial.


Question: I’m working on an android app for object detection, although examples are provided on the tensorflow website, it’s not exactly what I’m looking for, and I want to create this project from scratch. I can’t find any free course or tutorial on the topic, the examples provided in tensorflow.org are too complex for me as a beginner. Other tutorials I find always require to download pre-written code on github, then show how to customize it. Instead of showing how everything works.

Context:
HI, for a full tutorial I’d follow this:

On-Device Machine Learning  |  Google Developers 2

There’s a full set of tutorials to go from zero to model deployed. It might be able to help you


Tensorflow HUB - transfer learning for object detection

Question:
Hi all,
I am having some trouble with applying transfer learning in object detection models.
The documentation provides a nice tutorial for transfer learning in classification models (Retraining an Image Classifier  |  TensorFlow Hub 3). However, I couldn’t find anything similar for the object detection case.
I tried to readapt the object detection tutorial (TensorFlow Hub Object Detection Colab 3) according to the classification tutorial linked above, but I didn’t manage to progress much and got a bunch of errors that couldn’t solve.
Does anyone have any suggestion in this sense (or can suggest clear tutorials that explain this stuff)?
Thanks

Context:
neptune.ai – 30 Oct 20

How to Train Your Own Object Detector Using TensorFlow Object Detection API -... 51

  Object detection is a computer vision task that has recently been influenced by the progress made in Machine Learning.  In the past, creating a custom object detector looked like a time-consuming and challenging task. Now, with tools like...

    Est. reading time: 28 minutes


Question:
I downloaded the csv data of boston house price to practice tensorflow; the csv data have 13 columns and the number 13 column is the price;
I processed the data and send them into the model to tranining;
But the training result is that the loss is a negative number and the absolute value of loss is become bigger and bigger per epoch. And the accuracy is always 0 simutaneously.
So is there any wrong with my code when process the csv data or create the model?
please help me!
import tensorflow as tf
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

f = open('bostonHouse.csv')

df = pd.read_csv(f)
data = np.array(df)
plt.figure()
plt.plot(data)
plt.show()

normalize_data = (data - np.mean(data)) / np.std(data)
normalize_data = normalize_data[:, np.newaxis]

train_x, train_y = [], []
for i in range(len(normalize_data)):
    x = normalize_data[i][0][:12]
    y = normalize_data[i][0][12]
    train_x.append(x.tolist())
    train_y.append(y.tolist())

print("train_x data:{}".format(train_x[:1]))
print("train_y data:{}".format(train_y[:1]))
print('train x len', len(train_x[0]))
model = tf.keras.Sequential([
    tf.keras.layers.Dense(128, activation='relu', input_shape=(12,)),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(1, activation='sigmoid')
])

model.compile(
    loss="binary_crossentropy",
    optimizer='adam',
    metrics=['accuracy'],
)

model.summary()
model.fit(x=train_x, y=train_y, epochs=20)

QQ截图202110101256072195×679 82.4 KB

Context: the loss is negative number and the accuracy is always 0


28x28 image is still 28x28 after applying 7x7 kernel?

Question:
How is that possible?
input image 28, 28, 1 x 60,000
Applied conv2d filter of 64,7 (64 filters, 7x7 kernel)
if I print out the model’s first layer output is still 28x28
model=keras.models.Sequential([
keras.layers.Conv2D(64, 7, activation=“relu”, padding=“same”, input_shape=[28, 28, 1]),
keras.layers.MaxPooling2D(2), \
X_train_full.shape:  (60000, 28, 28, 1)
X_train_full.dtype:  uint8
X_test shape:  (10000, 28, 28)
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/init_ops.py:1251: calling VarianceScaling.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
conv2d (Conv2D)              (None, 28, 28, 64)        3200
_________________________________________________________________

Context:
This is because you have specified padding="same", which results in the output having the same “size” (height & width dimensions) as the input.
You can find additional details here: tf.keras.layers.Conv2D  |  TensorFlow Core v2.6.0 1


Question:
I have been using TF for quite some time and decided to try the Tensorflow Profiler notebook, TensorFlow Profiler: Profile model performance | TensorBoard 4
However, I got an error messages while running it on my Windows 10 PC. It failed to load libcupti. I am wondering if I can get some help here so that I can continue the profiling effort. Thank you.
David

Context:
I found an answer to my own question: python - Tensorflow CUDA - CUPTI error: CUPTI could not be loaded or symbol could not be found - Stack Overflow 92
I tried the 3rd post after the question and it works!


Question:
Hi Forum, I’ll start by mentioning I’m a newbie on this forum, so sorry if I repeat an existing thread. I searched but did not find one. For a research project, I’m interested in using an existing Stanford Protégé ontology as a model to teach Tensorflow to create a system that will allow me to make predictions based on the ontology. In previous iterations of the project, I was able to use StarDog to something similar but I now want to investigate using Tensorflow for this purpose.
So my question is, does anyone here have some ideas on where I could find information on using Stanford Protégé ontology with Tensorflow?

Context:
I don’t know anything specific for this ontology and TF but more in general if you want to find an entry point in this specific field between ontology reasoning and deep learning I suggest to take a look at:

      arXiv.org

Ontology Reasoning with Deep Neural Networks 7

  The ability to conduct logical reasoning is a fundamental aspect of
intelligent human behavior, and thus an important problem along the way to
human-level artificial intelligence. Traditionally, logic-based symbolic
methods from the field of...


TensorBoard help on Keras Beginner Tutorial: Overfit and underfit

Question:
Hi,
I copied exactly and ran the “Overfit and underfit” tutorial on PyCharm IDE, but was unable to visualize the data on TensorBoard with the following output: “No dashboards are active for the current data set.”. I suspect the program is logging the data to and loading the data from two different directories, but I don’t know how to check that or if that is the case at all. Any idea, how I can troubleshoot this?
Thanks.

Context:
When you work in PyCharm you create a “Project” - a folder where all your code and data files are located. To use a TensorBoard you should create a subfolder in this project folder and call it, for example, “logs”.
To define a relative path to this “logs” subfolder, which is one level below the folder with the code file, you use . as an identifier of the current working directory like this:
log_dir = "./logs/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)

When you run the code, you can manually check that new content is automatically loaded in the “logs” folder.
To activate TensorBoard you launch the terminal from the bottom of PyCharm window. There you should be able to see the absolute path to your “Project” folder starting from the C: drive.
You enter the command with a relative path: tensorboard --logdir ./logs/
Together with the absolute path to the “Project” folder this relative path should be a correct path to the “logs”. Errors appear if there is any inconsistency in this path. Like if your code file is located not in the main project folder but is some other place. Then you should carefully define the relative path to the logs.
You can also consult the documentation: Get started with TensorBoard  |  TensorFlow 1


How can I generate tflite from the Kaggle dataset

Question:
Hi,
I have dataset steelcount | Kaggle 1 from kaggle site
now I wanted to generate the tflite file to use in my flutter app.
Please guide me is there any tool out there which help me achieve this task because I am not expert to ML but once I have tflite file I can program my app easily.
Any good help from the community would be great.
Thanks

Context:
Have you already explored:

      github.com

GitHub - am15h/tflite_flutter_plugin: TensorFlow Lite Flutter Plugin 2

  TensorFlow Lite Flutter Plugin. Contribute to am15h/tflite_flutter_plugin development by creating an account on GitHub.

P.s. you can convert your Keras/TF regular trained model with:

      TensorFlow

TensorFlow Lite converter 1


Question:
I have recently run a model on a custom dataset. Deployed it in the android app. When I run it in the android app it prints out  random integers like 2.99231231,0.2742424,-0.9953453,-0.775656.
Can someone tell me what is meaning of this?
How can I know what tflite.model outputs.
Please answer in details.
Thank You.

Context:
Hi @Varun_Singh
Please explain what sort of model is this so we can assess the “integer” outputs. Also upload it somewhere so we can view it on netron.app
Best


Quantize Activations. What values are quantized?

Question:
Hey,
My question is related to quantize the activations to e.g. int8 using a representative dataset. Assume a sigmoid activation function in the following.
What confuses me: Which parameters are scaled&shifted / quantized?
I understand that we monitor the common output activations to determine min and max ranges. What do we do with these values? My intuition would say, that we need to scale the entire activation function, because in case of a sigmoid, quantized input (e.g. some high int8 value caused by quantized weights) would always lead to saturated values (near 1 or 0).
Would be glad if any could clear my confusion.

Context:
Hey,
from a lot of sources I went through now, I do not understand what exactly is quantized in the activations. Assume a sigmoid activation function. I can observe (using a representative dataset) a bunch of activation outputs, using the unquantized float32 weights. Then I determine the min,max range, but what do I do with that determined scale factor afterwards? My intuition says I need to quantize the entire activation function somehow (or dequantize the activation input), because e.g. a regular sigmoid cant deal with quantized (e.g. int8) input values and would always end in the saturated area. In other words, I dont really get the quantization of activations. Please clear up my confusion.


Question:
From keras.layers.RNN 1, the RNN layer has a reset_state() method that can reset the state of the RNN. However, this method takes in a list of numpy arrays instead of Tensors, so if I were to invoke this method inside the call of a model subclass when eager execution is disabled like:
def call(self, x, training=False,   **kwargs):
    ...
    original_state = [i.numpy() for i in self.rnn_layer.states]
    ...
    self.rnn_layer.reset_states(states = original_state)
    ...

I would get an error saying numpy() is only available when eager execution is enabled. Is there some way to do what I want above regardless of whether eager execution is enabled or disabled? I thought maybe add_update() method might be the solution (per this StackOverflow post 1) but I was unable to get it to reset to the original state.

Context:
IIUC self.states will return you the variables containing the states.
You should be able to use var.assign(x) to update them.
But the code may be clearer if you use stateful=False and return_states=True. Then you have direct control of the states, you don’t have to reach into the RNN to edit the.


Modifying the display progress bar during model.fit

Question:
Currently the progress bar during model.fit looks like the following (with metrics = [‘mae’]):

Epoch 1/5
1/1 [==============================] - 4s 4s/step - mae: 0.0365 - val_loss: 0.7191 - val_mae: 0.7191
Epoch 2/5
1/1 [==============================] - 4s 4s/step - loss: 0.0000e+00 - mae: 0.0279 - val_loss: 0.1241 - val_mae: 0.1241

Is there any way to modify this such that only the metrics are displayed (remove both loss and val_loss)?

Context:
It looks like you might be able to do it by overloading the metrics property.

      github.com

    tensorflow/tensorflow/blob/master/tensorflow/python/keras/engine/training.py#L672-L683 1

          metrics = []
          if self._is_compiled:
            # TODO(omalleyt): Track `LossesContainer` and `MetricsContainer` objects
            # so that attr names are not load-bearing.
            if self.compiled_loss is not None:
              metrics += self.compiled_loss.metrics
            if self.compiled_metrics is not None:
              metrics += self.compiled_metrics.metrics

for l in self._flatten_layers():
            metrics.extend(l._metrics)  # pylint: disable=protected-access
          return metrics

But IDK what else could go wrong there.


Question:
I am confused, the documentation says that tensorflow.keras.layers.IntegerLookup exists tf.keras.layers.IntegerLookup | TensorFlow Core v2.6.0 3. But when I try to import it with from tensorflow.keras.layers import IntegerLookup I get: Cannot find reference ‘IntegerLookup’ in ‘init.py | init.py | tensorflow.keras.layers’
Am I misunderstanding the documentation or did I screw up the installation somehow? I am running Python 3.9 and tensorflow 2.6. I used pip install tensorflow to install tensorflow, I also tried Python 3.7 and Tensorflow 2.5 but I get the same message.

Context:
I think that probably there Is something wrong with your installation.
Can you reproduce this error in our official Docker image or on Google Colab?


How to configure padding_idx from Pytorch Embedding layer to TensorFlow

Question:
Hey guys,
I am trying to convert a project from Pytorch code to TensorFlow, and while going through the nn.Embedding layer there was this argument called padding_idx and wherever you have an item equal to padding_idx, the output of the embedding layer at that index will be all zeros.
But coming to TensorFlow’s Embedding layer there isn’t an argument close to padding_idx. Is there any way to leverage this functionality in TensorFlow?

Screenshot 2021-10-10 at 4.41.50 PM743×492 69.9 KB

Best,
Ashik.

Context:
Take a look at:

      Wook's Blog - Data is the new oil – 3 Mar 20

The Difference between Tensorflow and Pytorch using Embedding 12

  Compare Tensorflow and Pytorch when using Embedding.


Question:
Hi,
I went through the tutorials for the recommenders and what I’m missing it how to implement “candidate” features into the model.
For example lets say the model takes as an input user_id (or other user/features)   and returns media_title. How should I add other media /candidate features like genre to the training - but keeping the input the same for the model ?
Thanks.

Context:
This tutorial two features, title look up and embedding, to a candidate model (MovieModel).
Google for ‘tensorflow recommenders side features’


Question:
API describes:

      TensorFlow

tf.keras.layers.Conv2D  |  TensorFlow Core v2.6.0

  2D convolution layer (e.g. spatial convolution over images).

tf.keras.layers.Conv2D(    filters, kernel_size, strides=(1, 1), padding='valid',    data_format=None, dilation_rate=(1, 1), groups=1, activation=None,    use_bias=True, kernel_initializer='glorot_uniform',    bias_initializer='zeros', kernel_regularizer=None,    bias_regularizer=None, activity_regularizer=None, kernel_constraint=None,    bias_constraint=None, **kwargs)

followed by some example:
# The inputs are 28x28 RGB images with `channels_last` and the batch
# size is 4.
input_shape = (4, 28, 28, 3)
x = tf.random.normal(input_shape)
y = tf.keras.layers.Conv2D(
2, 3, activation='relu', input_shape=input_shape[1:])(x)
print(y.shape)

so I am assuming 2 filters, 3x3 kernel size etc.
Now the book I have shows the example specified large number of filters: 128, 64 etc, is it really accurate?

https://www.machinecurve.com/index.php/2020/03/30/how-to-use-conv2d-with-keras/

Secondly, I am also "porting" doing pytorch equivalent but pytorch's conv2d API has no mentions of filters, only significant params are: channels in / out and kernel size:

https://pytorch.org/docs/stable/generated/torch.nn.Dropout.html#torch.nn.Dropout

So how one specifies the filter in pytorch?

Context:
Plus I have following example, but when I print out the model, the input shape is 60k, 28, 28.
Then output of first conv2d layer is still 28, 28, how is that possible image is still 28, 28 even went through a kernel size of 7x7?
model=keras.models.Sequential([\
    keras.layers.Conv2D(64, 7, activation="relu", padding="same", input_shape=[28, 28, 1]),\
    keras.layers.MaxPooling2D(2), \

X_train_full.shape:  (60000, 28, 28, 1)
X_train_full.dtype:  uint8
X_test shape:  (10000, 28, 28)
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/init_ops.py:1251: calling VarianceScaling.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
conv2d (Conv2D)              (None, 28, 28, 64)        3200
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 14, 14, 64)        0
_________________________________________________________________
conv2d_1 (Conv2D)            (None, 14, 14, 128)       73856
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 14, 14, 128)       147584
_________________________________________________________________


Question:
I have a custom Keras layer as follows:
import tensorflow as tf
from tensorflow import keras
import numpy as np
from keras.models import Sequential
from keras.optimizers import RMSprop
from keras.optimizers import SGD
from keras.layers import Flatten

ig = 0.0
im = 0.5
iw = 0.88
isg = 0.2
ism = 0.2
isw = 0.2
eps=1e-7
pi=3.14
epoch_count = 1000
learning_rate = 0.001
sequence_len = 100

def w_initialization(dimension, activationrange = 2):
if type(dimension) is list and len(dimension) > 1:
input_dim = dimension[0]
output_dim = dimension[1]
elif type(dimension) is list:
input_dim = 0
output_dim = dimension[0]
else:
input_dim = 0
output_dim = dimension
return np.random.normal(loc=iw, scale=isw, size=dimension).astype('float32')

class NMU(keras.layers.Layer):
def **init**(self, output_dim, input_dim):
super(NMU, self).**init**()
self.weight = tf.Variable(w_initialization([input_dim, output_dim]), dtype="float32", name="weight", trainable=True)
def call(self, inputs):
W = tf.minimum(tf.maximum(self.weight , 0), 1)
output = (inputs * W)+1-W
return tf.reduce_prod(output, axis=1)

X_TRAIN = []
X_TEST = []

Y_TRAIN = []
Y_TEST = []

#DATASET
for x in range(1, 10000):
a1 = np.random.randint(1000)
a2 = np.random.randint(1000)
X_TRAIN.append(np.array([np.float32(a1), np.float32(a2)]))
Y_TRAIN.append(np.array([np.float32(a2*a1), np.float32(a2*a1)]))

for x in range(1, 10000):
a1 = np.random.randint(1000)
a2 = np.random.randint(1000)
X_TEST.append(np.array([np.float32(a1),np.float32(a2)]))
Y_TEST.append(np.array([np.float32(a2*a1), np.float32(a2*a1)]))

X_TRAIN = np.array(X_TRAIN)
X_TEST = np.array(X_TEST)
Y_TEST = np.array(Y_TEST)
Y_TRAIN = np.array(Y_TRAIN)

#MODEL
model = Sequential()
model.add(NMU(2,2))
model.compile(loss='mse', optimizer=RMSprop(lr=learning_rate))
model.fit(
validation_data=(X_TEST, Y_TEST),
x=X_TRAIN,
y=Y_TRAIN,
epochs=epoch_count,
callbacks=[keras.callbacks.EarlyStopping(monitor='val_loss', min_delta=0.0000001, patience=100, verbose=0)]
)

and I the following error:
tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [32,2] vs. [2,2] [[node sequential/nmu/mul (defined at nalu.py:135) ]] [Op:__inference_train_function_547]

Context:
I cannot reproduce your error:

      colab.research.google.com

Google Colaboratory 1


Question: Is there a way to create a confusion Matrix on Tflite Model Maker - Image Classification that is similar to Audio Classification?

Context:
Hi @Hagen_Hagen
Take a look at those notebooks for showing confusion matrix with sklearn and matplotlib:

      github.com

    farmaker47/Yamnet_Speech_commands/blob/main/Yamnet_Speech_commands.ipynb 4

    {
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Yamnet_Speech_commands.ipynb",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {

  This file has been truncated. show original

and

      github.com

    farmaker47/Yamnet_Speech_commands/blob/main/Yamnet_Plain_Speech_commands.ipynb 2

    {
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Yamnet_Plain_Speech_commands.ipynb",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {

  This file has been truncated. show original

Finally this one with Model maker classes:

      github.com

    farmaker47/Yamnet_Speech_commands/blob/main/Model_Maker_Speech_commands.ipynb

    {
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Model_Maker_Speech_commands.ipynb",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {

  This file has been truncated. show original

I think by combining you can print confusion matrix also for Image Classification task.
Best


RE: Building and Porting to armhf Machines

Question:
Hello,
I have a BBAI. From what I can tell, tensorflow-lite works on the BBAI but…

How can I port it to the BBAI after compilation from a Linux machine?

What steps do I need to take to make sure the .so file(s) are available on my BBAI/armhf machine?

Seth

Context:
Hello,
I am currently trying to build, also, on the Linux armhf machine. I will update everyone soon.
Seth
P.S. I got the Tensorflow-Lite installed on the BBAI via native compilation but I am receiving errors on running an example from here: https://github.com/tensorflow/examples/blob/master/courses/udacity_intro_to_tensorflow_lite/tflite_c01_linear_regression.ipynb
I will start a new thread.


Question:
Hi, I finally ran out of excuses to learn ML and Tensorflow.js, I’m building my first model and came across an error that I don’t quite understand where is coming from.
I have a basic model that takes an image and calculates a certain value, the input layer is a cropping layer that removes a number of pixels from the top and bottom of the image. The model works well, but when I change the settings of the cropping layer, say, remove 25 pixels from the top instead of 75, the browser (chrome) flickers and outputs the following error:

Screen Shot 2021-08-23 at 5.10.14 pm820×309 54 KB

NOTE: Right before the above error, it prints out the following message *Couldn't parse line number in error* followed by what appears to be GLSL code.
The same happens if I remove the cropping layer altogether.
I’m using tfjs v3.8.0 but also tested with v2.0.0 with similar outcomes. This is my model:
const model = tf.sequential();

// Cropping Layer
model.add(
  tf.layers.cropping2D({
    // If I change 75 to anything below 50, it crashes before completing the first epoch,
    // If this layer is removed, it crashes almost immediately after training starts
    cropping: [
      [75, 25],
      [0, 0]
    ],
    // image height, width, depth
    inputShape: [160, 320, 3]
  })
);

model.add(
  tf.layers.conv2d({
    filters: 16,
    kernelSize: [3, 3],
    strides: [2, 2],
    activation: 'relu',
  })
);

model.add(
  tf.layers.maxPool2d({
    poolSize: [2, 2]
  })
);

model.add(
  tf.layers.conv2d({
    filters: 32,
    kernelSize: [3, 3],
    strides: [2, 2],
    activation: 'relu'
  })
);

model.add(
  tf.layers.maxPool2d({
    poolSize: [2, 2]
  })
);

model.add( tf.layers.flatten());
model.add( tf.layers.dense({ units: 1024, activation: 'relu' }));
model.add( tf.layers.dropout({ rate: 0.25 }));
model.add( tf.layers.dense({ units: 128, activation: 'relu' }));
model.add( tf.layers.dense({ units: 1, activation: 'linear' }));

model.compile({
  optimizer: 'adam',
  loss: 'meanSquaredError',
  metrics: [
    'accuracy',
  ],
});

Am I doing something obviously wrong?
Thanks.

Context:
Welcome to the forum and thank you for sharing your work. Let me look into this with our team to find out what may be going on here. You may have found a bug. In the meantime would you be able to share with us a live working (or not working in this case) demo of the bug eg on Codepen.io 2 or Glitch.com 2 so we can inspect it live?
Thank you!


How to place earrings/ jewellery on face?

Question:
HI,
I am able to execute this demo: https://github.com/tensorflow/tfjs-models/tree/master/face-landmarks-detection 1 (&pose detection demo) Finally I am able to see the face mesh on top of my face. I am able to see the shoulder lines, dots etc.
Now I want to place some 3d model (example earrings/ necklace/ spects/ Hat/ Beard ) on these dots detected by the above project. I am unable to find any tutorial/ leads. Any help?

Context:
So a number of folk from our community have managed to overlay things like face masks etc so they may be best placed to answer this as this is more about a co-ordinate system transformation if I remember correctly.
Essentially you have 2 co-ordinate systems - one is the real world (camera view) and the other is three.js virtual world - they are 2 different systems.
You will need to make your own custom mapping to take data from one and use in the other.
This guy from the community has successfully done things in this space and probably has the most well implemented examples he may be able to share with you (or check his github as it may already be there):

      twitter.com

Jaume Sanchez Elias (thespite) 4

  It rubs the lotion on its skin...

  4:11 PM - 3 May 2020

      18

      1


RE: Making Examples Run on ARMHF Machines

Question:
Hello,
I am working from here: https://github.com/tensorflow/examples/blob/master/courses/udacity_intro_to_tensorflow_lite/tflite_c01_linear_regression.ipynb .
I am receiving this error:

  File "/home/debian/MyFirstTensor.py", line 52
    tf_results = model(tf.constant(input_data))
    ^
SyntaxError: invalid syntax

I tried some relative coding exchanges but nothing seems to be working. Does this Colab still work?
Seth
P.S. This is the entire source:

import tensorflow as tf
import pathlib
import numpy as np
import matplotlib.pyplot as plt

from tensorflow.keras.models import Model
from tensorflow.keras.layers import Input

# creating Keras Model!
x = [-1, 0, 1, 2, 3, 4]
y = [-3, -1, 1, 3, 5, 7]

model = tf.keras.models.Sequential([
    tf.keras.layers.Dense(units=1, input_shape=[1])
])

model.compile(optimizer='sgd', loss='mean_squared_error')
model.fit(x, y, epochs=200, verbose=1)

# generating the saved model!
export_dir = 'saved_model/1'
tf.saved_model.save(model, export_dir)

# converting the saved model!
converter = tf.lite.TFLiteConverter.from_saved_model(export_dir)
tflite_model = converter.convert()

tflite_model_file = pathlib.Path('model.tflite')
tflite_model_file.write_bytes(tflite_model)

# initialize the TFLite interpreter!

# Load the TFLite model and allocate tensors...
interpreter = tf.lite.Interpreter(model_content=tflite_model)
interpreter.allocate_tensors()

# Getting input and output tensors...
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

# Testing the TensorFlow Lite model on random input data...
input_shape = input_details[0]['shape']
inputs, outputs = [], []
for _ in range(100):
    input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)
    interpreter.set_tensor(input_details[0]['index'], input_data)

    interpreter.invoke()
    tflite_results = interpreter.get_tensor(output_details[0]['index']

    # Testing the Tensorflow model on random input data...
    tf_results = model(tf.constant(input_data))
    output_data = np.array(tf_results)

    inputs.append(input_data[0][0])
    outputs.append(output_data[0][0])

plt.plot(inputs, outputs, 'r')
plt.show

# download the TFLite model file!
try:
    from google.colab import files
    files.download(tflite_model_file)
except:
    pass

Context:
Hello,
Please forgive me and my attitude. I am done. The source works just fine.
Seth


How to convert the model trained by unsupervised learning (such as kmeans) with tensorflow lite?

Question: Can I use tensorflow lite to convert the model trained by unsupervised learning (such as kmeans)?How to achieve it ? Thanks!

Context:
Hi,
Was your kmeans model trained using TensorFlow?
if so, you can try the TFLite converter: TensorFlow Lite converter 3


Load custom Data into a tensorflow pipeline

Question:
0
I am trying to implement this code which loads the data from the
official tensorflow dataset to get it to load my data placed on my google drive
dataset, metadata = tfds.load('cycle_gan/horse2zebra',
                              with_info=True, as_supervised=True)
train_horses, train_zebras = dataset['trainA'], dataset['trainB']

How can I get it to load my images into classes from classes A and B to my train_horses and train_zebras class
train_dataset=tf.keras.utils.image_dataset_from_directory(
    '/content/drive/MyDrive/ColorGan', labels='inferred', label_mode='int',
    class_names=None, color_mode='rgb', batch_size=32, image_size=(256,
    256), shuffle=True, seed=2000, validation_split=0.2, subset='training',
    interpolation='bilinear', follow_links=False,
    crop_to_aspect_ratio=False)
test_dataset=tf.keras.utils.image_dataset_from_directory(
    '/content/drive/MyDrive/ColorGan', labels='inferred', label_mode='int',
    class_names=None, color_mode='rgb', batch_size=32, image_size=(256,
    256), shuffle=True, seed=2000, validation_split=0.2, subset='validation',
    interpolation='bilinear', follow_links=False,
    crop_to_aspect_ratio=False)

train_horses, train_zebras = train_dataset['A'],train_dataset['B']

It gives me error that it is not scriptable what can I so that the data loads in the format shown in the top code snippet

Context:
You should be getting a batched dataset object, where labels are represented by integers. You cannot use square brackets to extract elements from it. That’s the meaning of “not subscriptable” error.
To see what is inside the first batch you can use a for loop:
for x, y in train_dataset.take(1):
    print('Inputs:', x, 'Labels:', y)

I’m not sure why you want to separate the classes, but it could be accomplished with a filter() function. Please, see the documentation here: tf.data.Dataset | TensorFlow Core v2.6.0 1


Creating dataset with audio and its captions

Question: I have audio files (in .wav) and their corresponding captions. I’m slowly researching and creating a model to transcribe the audio into text. The audio files are mostly short length, average of 12 seconds duration. But how would I do that? Is there a way to create a custom TF dataset that has can take audios in a column and its captions in another?

Context:
I’d format my dataset similar to others that have similar objective like the librispeech: librispeech  |  TensorFlow Datasets 3
That will help you train a model later as there are many examples already based on the the librispeech dataset


How to install TensorFlow 2 with GPU support on Linux without super user privileges?

Question:
The Linux is remote, a node in a cluster, not a desktop in front of me, so I don’t have full control. I’m just a normal user having no super user privileges. I can only read and write within my own user space. I can only login using SSH.
CUDA 11.0.3 is installed in Linux, but cnDNN isn’t.
The graphics hardware is powerful enough that TensorFlow 2 is happy to work with.
Python 3.8.6 and pip 20.1.1 is installed in Linux.
gcc 10.2.0 is installed.
Docker is not installed.

My question is: how to install TensorFlow 2 with GPU support on Linux without super user privileges, if possible at all? Alternatively, is it possible to install Docker in my user space and then install TensorFlow 2 with GPU in Docker? The ultimate result is that I can run
python3 -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
as in TensorFlow 2 install webpage. Step-by-step instructions will be appreciated, but a link referring to an external webpage containing working  step-by-step instructions is also ok (I didn’t find it). Thank you.

Context: I’ve not tested personally with a GPU configuration but you can try to use Docker rootless with our official GPU image.


How can I specialize my model for precision, and make it default to an output if it is not certain enough to sacrifice accuracy?

Question:
Hello. I am trying to create a classification model, but my data has very high variance.
There are 3 Classes and 7 Categories for each of them (1,2,3,4,5,6,7), and after analyzing my model,
it seems impossible to go anywhere higher than 30% Accuracy if it attempts to predict the exact value.
So I created a custom metric, which measures accuracy by grouping the 7 categories into only 3 to
make it easier for the model. 1,2,3 are grouped, 5,6,7 are grouped, and theres 4.
So, I want my model to default to an output (4 in this case) if none of the input variables are enough of a clue to predict the category of each class. How would I do that?
My current idea is to add 1 for correct predictions, 0 for incorrect ones, but still add 0.5 when 4 is selected, to make my model realize it is safe to keep outputting 4 if it is not sure, but still make it
risk having to guess when it believes it has enough clues.
It did not work well. Any ideas? I will be thankful for any attempt to help.

Context:
Maybe one solution (aside the obvious of trying to improve your model accuracy) is to post process the results outside your model.
your model gives an answers → you compare to a threshold → if not good enough, return the default value


Question:
Hi,
I am working on my FYP to build a text to speech in Urdu language. i currently building my data set. i want to know which audio features is best for machine learning. i try MFCC but when i reconstruct its audio the result is very bad.
I know how to do it for one feature. but i want to use more features in my data set but i do not know how to use two or more features output and convert it into audio.
Means the how output audio features will reconstruct into audio file.
any python library?
please help me its urgent

Context:
Asalam-o-alaikum
kindly contact with me i also pick this project for my FYP


Bert-based QA can’t answer yes/no questions

Question:
The TFJS BERT-based QA demo (https://storage.googleapis.com/tfjs-models/demos/mobilebert-qna/index.html 6) can answer “Where was Tesla born?” but not “Was Tesla born in the Austrian Empire?”.
In general, it doesn’t seem to be able to answer yes/no questions. Why is that?

Context:
I think that these models could be still finetuned on BoolQ style QA datasets :

      paperswithcode.com

Papers with Code - BoolQ Benchmark (Question Answering) 4

  The current state-of-the-art on BoolQ is T5-11B. See a full comparison of 7 papers with code.


Question:
I want to run TensorFlow pose detection on the WebRTC video chat web through Firebase.
However, the video brought through the server cannot be pose-detected, and errors continue to occur that there is no ‘onloded data’.
Is there a good way to solve it?

Context:
Do you have a link to the live demo or provide the exact errors. It is hard to debug without these details. My guess however is that you need to:

Serve the webpage over HTTPS if trying to use webcam - else access will be denied.

Ensure CORS headers are set for video from remote sources or domains else your HTML Canvas will be tainted and not accessible in JavaScript. Please check resources on CORS if this is the issue:

      developer.mozilla.org

Allowing cross-origin use of images and canvas - HTML: HyperText Markup... 3

  HTML provides a crossorigin attribute for images that, in combination with an appropriate CORS header, allows images defined by the  element that are loaded from foreign origins to be used in a  as if they had been loaded from the current origin.

If you want a website that allows you to host simple websites for free on https and try out HTML/CSS/JS ideas check out Glitch.com 1. We even have a presence on there where you can fork our already working code as a starting point eg getting webcam imagery etc and classifying it.


Passing local video through tf instead of using webcam

Question:
Hi Everyone! Not sure if this is the right place to ask this, but I’m trying to use a local video instead of the webcam for this Teachable Machine/TF js script. File2 is functional code that uses the webcam and passes the video through the model. File1 is my attempt at using a local video instead of the webcam, but doesn’t currently work. I’m seeking help with passing the video through the model in File1.
I’m still a JS beginner, so any help is greatly appreciated!
Thanks!
File 1:
 <input type="file" name="file" id="fileItem" onchange="onChange()">

 <button type="button" onclick="init()">Start</button>
 <video id="webcam-container" controls></video>

File 2: (Functional)
<button type="button" onclick="init()">Start</button>

Context:
Welcome to the community. This is more a question about web programming vs TensorFlow.js itself but I shall try to point you in the right direction. You may want to use some code like this to grab a local file and play it in a video tag (this pen also contains code to load a random TensorFlow.js model and use it to classify a frame of the video when you click the classify button below the video).

Once you have video rendered to canvas you can then pass the canvas to TensorFlow.js pre-made models for classification as usual (or grab a frame from the canvas and convert to Tensor if running on a custom model yourself).
Key things to note:
Your webpage must be served on HTTPS (secure) to access files without issues I believe. You can use Codepen like I did to get free HTTPS page to test on, or:

Glitch.com 1 offers free projects hosted on https. We even have a presence on there ourselves for example code
You could sign up for something like Google Cloud Storage bucket which serves over HTTPS too. But this is a paid service (but will scale to as many users as you need)


[Voice Recognition] How can I use the model?

Question:
I’m no audio expert, but voice recognition is one of those fields that I  really wanted to explore.
I been following the tensorflow wiki regarding this matter.

      TensorFlow

Simple audio recognition: Recognizing keywords  |  TensorFlow Core 1

In order to create a model I used my personal recordings with some of my friends. I notice that the model could only receive audio samples with size 31.2kb(format.wav)
After training this model, I successfully saved it along with the classes with the following code:
#Saving model
print("Saving model and label")
model.save("models/model_"+str(test_acc)+"_"+'{:%Y-%m-%d}'.format(datetime.datetime.now())+".h5")
f = open("models/labels_"+str(test_acc)+"_"+'{:%Y-%m-%d}'.format(datetime.datetime.now())+".pickle", "wb")
f.write(pickle.dumps(commands))
f.close()

Now I wanted to be able to given a 5 mins audio file or a stream of audio, use this model to verify if a given word was said any ideas how could this be accomplished?
Currently, I’m abit clueless what to do now. The following code is able to currently classify a 31.2kb, but what I really want is to classify bigger audio files and a better way to use the model.
import os
import pathlib

import datetime
import pickle
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import tensorflow as tf

from tensorflow.keras.layers.experimental import preprocessing
from tensorflow.keras import layers
from tensorflow.keras import models
from IPython import display

print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))

def get_waveform_and_label(file_path):
  #Label
  path = tf.strings.split(file_path, os.path.sep)
  label = path[-2]

  #Decode Audio
  audio_binary = tf.io.read_file(file_path)
  audio, _ = tf.audio.decode_wav(audio_binary)
  waveform = tf.squeeze(audio, axis=-1)

  return waveform, label

def get_spectrogram(waveform):
  # Padding for files with less than 16000 samples
  zero_padding = tf.zeros([16000] - tf.shape(waveform), dtype=tf.float32)

  # Concatenate audio with padding so that all audio clips will be of the
  # same length
  waveform = tf.cast(waveform, tf.float32)
  equal_length = tf.concat([waveform, zero_padding], 0)
  spectrogram = tf.signal.stft(
      equal_length, frame_length=255, frame_step=128)

  spectrogram = tf.abs(spectrogram)

  return spectrogram

def get_spectrogram_and_label_id(audio, label):
  spectrogram = get_spectrogram(audio)
  spectrogram = tf.expand_dims(spectrogram, -1)
  return spectrogram

def preprocess_dataset(files):
  files_ds = tf.data.Dataset.from_tensor_slices(files)
  output_ds = files_ds.map(get_waveform_and_label, num_parallel_calls=AUTOTUNE)
  output_ds = output_ds.map(get_spectrogram_and_label_id,  num_parallel_calls=AUTOTUNE)
  print(output_ds)
  return output_ds #return tuple (spetogram, label)

print("Loading model")
model = tf.keras.models.load_model('models/model_0.8_2021-10-04.h5')
CLASS_NAMES = pickle.loads(open("models/labels_0.8_2021-10-04.pickle", "rb").read())

data_dir = pathlib.Path('recordings')
if not data_dir.exists():
    print("Unable to load recordings")

AUTOTUNE = tf.data.AUTOTUNE
#sample_file = data_dir/'kekeres/testB.wav'
sample_file = data_dir/'kekeres/kekeres_1633285520639.wav'
sample_ds = preprocess_dataset([str(sample_file)])

for spectrogram in sample_ds.batch(1):
  prediction = model(spectrogram)
  prediction_data = tf.nn.softmax(prediction, axis=1).numpy()

  index = tf.argmax(prediction, axis=1)
  print("class: "+str(CLASS_NAMES[np.array(index)]))
  print("confidence: "+str(prediction_data[0][np.array(index)]))

Context: Can you split 5min wave into smaller parts and then feed it to network?


Question:
Hello,
I’m using:

python 2.5.3
tensorflow 2.3.0

What error am I making?
Thanks!
import tensorflow as tf
import numpy as np
import cv2
from PIL import Image

interpreter = tf.lite.Interpreter(model_path="mobilenet_v1_1.0_224_quant.tflite", num_threads=None)
#model_path="model.tflite", num_threads=None)

interpreter.allocate_tensors()

input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

# check the type of the input tensor
floating_model = input_details[0]['dtype'] == np.float32

# NxHxWxC, H:1, W:2
height = input_details[0]['shape'][1]
width = input_details[0]['shape'][2]
img = Image.open("test.jpg").resize((width, height))
# add N dim
input_data = np.expand_dims(img, axis=0)
if floating_model:
  input_data = (np.float32(input_data) - 127.5) / 127.5

interpreter.set_tensor(input_details[0]['index'], input_data)

interpreter.invoke()

print(interpreter.get_tensor(output_details[0]['index']))
print(interpreter.get_tensor(output_details[1]['index']))
print(interpreter.get_tensor(output_details[2]['index']))
print(interpreter.get_tensor(output_details[3]['index']))
Error:
print(interpreter.get_tensor(output_details[1][‘index’]))
IndexError: list index out of range

Context:
Hi @Marcelo_Aragao
First of all print the whole output details to see the shape and if it has ‘index’ info inside.


Question: I need to check for stationarity of the time series. How can this be done using tensorflow?

Context:
You can reference this tutorial on predicting time series data: Time series forecasting  |  TensorFlow Core 8
It does not require to check for stationarity before training the model. However, in some cases the model will benefit if you generate rolling and cumulative features based on the original time series values.
If you asked about the functions similar to those that are available in statsmodels, I did not come across a ready solutions. TF is a huge library. Probably you can do something with tf.math.segment_mean function or other math functions.


Adding a constant to a batch data set in preparing time series data in Tensorflow

Question:
Consider the code below. The batch data is created with the command tf.keras.preprocessing.timeseries_dataset_from_array. I want to manipulate every array in the batch data in such a way that i want to add the constant “99” to it. The variable feature_ds contains the batch data sets.
import tensorflow as tf
import numpy as np

simple_data_samples = np.array([
         [1, 1, 1, -1, -1],
         [2, 2, 2, -2, -2],
         [3, 3, 3, -3, -3],
         [4, 4, 4, -4, -4],
         [5, 5, 5, -5, -5],
         [6, 6, 6, -6, -6],
         [7, 7, 7, -7, -7],
         [8, 8, 8, -8, -8],
         [9, 9, 9, -9, -9],
         [10, 10, 10, -10, -10],
         [11, 11, 11, -11, -11],
         [12, 12, 12, -12, -12],
])

def print_dataset(ds):
    for inputs, targets in ds:
        print("---Batch---")
        print("Feature:", inputs.numpy())
        print("Label:", targets.numpy())
        print("")

def timeseries_dataset_multistep_combined(features, label_slice, input_sequence_length, output_sequence_length, batch_size):
    feature_ds = tf.keras.preprocessing.timeseries_dataset_from_array(features, None, input_sequence_length + output_sequence_length, batch_size=batch_size)

    def split_feature_label(x):

        return x[:, :input_sequence_length, :], x[:, input_sequence_length:, label_slice]

    feature_ds = feature_ds.map(split_feature_label)

    return feature_ds

ds = timeseries_dataset_multistep_combined(simple_data_samples, slice(3, None, None), input_sequence_length=4, output_sequence_length=2, batch_size=2)
print_dataset(ds)

Context:
If you want to add the same constant to all of the input data, you can simply create some preprocessing function, which adds this number to the original numpy arrays.
If you want to use add operation inside the model, you can check out the documentation for tf.math.add and tf.karas.layers.Add.


Tensorflow model (with input mel spectrograms) on kaggle runs on CPU instead of GPU

Question:
I am using librosa along with tensorflow. More specifically, I am using a generator, where I convert audio .wav files to log-mel spectrogram, delta and delta-delta.
I have a model consisting of CNN layers.
I run the script in kaggle.
However, my model does not use the GPU. It runs on CPU and is extremely slow.
Here is the code, if anyone can help.
class BerGenerator(tf.keras.utils.Sequence):
    def __init__(self, X_train, y_train, batch_size = 16):

        self.batch_size = batch_size
        self.X_train = X_train
        self.y_train = y_train
        self.indexes = np.arange(len(self.X_train))
        self.on_epoch_end()

    def __len__(self):

        return len(self.X_train) // self.batch_size

    def __getitem__(self,idx):

        indexes = self.indexes[idx * self.batch_size : (idx + 1) * self.batch_size]
        batch_audios = self.X_train[indexes]
        batch_labels = self.y_train[indexes]
        X = np.empty([self.batch_size, 224, 224, 3])

        for audio in batch_audios:
            i = 0
            #print(audio)
            path = '../input/audio-files/audio_files/' + str(audio)
            x, sr = librosa.load(path)
            ps = librosa.feature.melspectrogram(y=x, sr=sr,n_mels=224, hop_length = 512)
            ps_db= librosa.power_to_db(ps, ref=np.max) #log-mel spectrogram (2d - [n_mels,t])
            delta = librosa.feature.delta(ps_db) #delta (2d)
            delta2 = librosa.feature.delta(ps_db, order=2) #delta-delta (2d)
            ps_db = tf.expand_dims(ps_db, axis = -1)     #3d ([n_mels,t,1])
            delta = tf.expand_dims(delta, axis = -1)     #3d
            delta2 = tf.expand_dims(delta2, axis = -1)   #3d
            final_map = tf.concat([ps_db, delta, delta2], axis=-1)
            resized_map = tf.image.resize(final_map, [224,224]).numpy()   #[224,224,3]
            #print(resized_map)
            X[i,:,:,:] = resized_map                             #[batch_size, 224, 224, 3]
            i = i + 1

        return np.array(X), np.array(batch_labels)

    def on_epoch_end(self):
        # Shuffle indexes after each epoch if shuffle is set to True.
        np.random.RandomState(42).shuffle(self.indexes)

X = dataset['audio']
y = dataset['label']
X = np.array(X.tolist())
y = np.array(y.tolist())

#skf = RepeatedStratifiedKFold(n_splits = 10, n_repeats = 3)
skf = StratifiedKFold(n_splits = 10)

def create_model():

    inp = Input(shape=(224, 224, 3,), dtype="float32")
    img_1 = Conv2D(16, kernel_size=(3, 7), activation=activations.relu)(inp)
    img_1 = Conv2D(16, kernel_size=(3, 7), activation=activations.relu)(img_1)
    img_1 = MaxPool2D(pool_size=(3, 7))(img_1)
    img_1 = Dropout(rate=0.1)(img_1)
    img_1 = Conv2D(32, kernel_size=3, activation=activations.relu)(img_1)
    img_1 = Conv2D(32, kernel_size=3, activation=activations.relu)(img_1)
    img_1 = MaxPool2D(pool_size=(3, 3))(img_1)
    img_1 = Dropout(rate=0.1)(img_1)
    img_1 = Conv2D(128, kernel_size=3, activation=activations.relu)(img_1)
    img_1 = GlobalMaxPool2D()(img_1)
    img_1 = Dropout(rate=0.1)(img_1)

    dense_1 = BatchNormalization()(Dense(128, activation=activations.relu)(img_1))
    dense_1 = BatchNormalization()(Dense(128, activation=activations.relu)(dense_1))
    dense_1 = Dense(1, activation='sigmoid')(dense_1)

    model = Model(inputs=inp, outputs=dense_1)

    return model

accuracy = []
precision = []
recall = []
auroc = []
specificity = []
for fold, (train_index, test_index) in enumerate(skf.split(X, y)):
    X_train, X_test = X[train_index], X[test_index]
    y_train, y_test = y[train_index], y[test_index]
    X_train, X_eval, y_train, y_eval = train_test_split(X_train, y_train, test_size=0.2, random_state=42)
    print("Currently on fold: {}".format(fold))

    model = create_model()

    model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate = 0.001),loss="binary_crossentropy",metrics=["acc",tf.keras.metrics.Recall(), tf.keras.metrics.Precision(),tf.keras.metrics.AUC(),
                                                                                tf.keras.metrics.TrueNegatives(),tf.keras.metrics.FalsePositives()])

    train_data = BerGenerator(X_train,y_train,batch_size=2)
    eval_data = BerGenerator(X_eval,y_eval,batch_size = 2)
    history = model.fit(train_data, epochs=1000, verbose = 1, class_weight = class_weight_function(y_train),validation_data=eval_data,callbacks = [tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=10),
                                                                                tf.keras.callbacks.ReduceLROnPlateau(monitor='val_loss', mode = 'min',
                                                                                factor=0.1, patience=3)])
    test_data = BerGenerator(X_test,y_test,batch_size=4)
    result = model.evaluate(test_data, verbose=0)
    print(result[1], result[2],result[3], result[4], result[5]/(result[5]+result[6]))

I get the following warnings:
2021-10-04 20:32:47.111506: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization passes are enabled (registered 2)
2021-10-04 20:32:47.115770: I tensorflow/core/platform/profile_utils/cpu_utils.cc:112] CPU Frequency: 2000144999 Hz
2021-10-04 20:32:48.883555: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.11
2021-10-04 20:32:49.779140: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.11
2021-10-04 20:32:53.569330: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8
Thank you.

Context:
Hi Loukas,
When I did audio classification, I tried to leave all preprocessing (like librosa and correlated) on preprocessing layers, maybe restructuring the pipeline might fix: Transfer learning with YAMNet for environmental sound classification 5


Build Serving Image with Multiple Models

Question:
I don’t have a problem when creating my own serving image in docker using 1 model but when I try to build a serving image with multiple models it doesn’t work.
Here’s the command I used
Create Serving Image

docker run -d --name serving_base tensorflow/serving

Copy SavedModel

docker cp /home/model1 serving_base:/models/model1
docker cp /home/model2 serving_base:/models/model2
docker cp /home/model.config serving_base:/models/model.config

Commit

docker commit serving_base acvision

Stop Serving Base

docker kill serving base

Checking docker image

image716×129 36.6 KB

docker run --rm --name serve_acvision -p8500:8500 -p8501:8501 -d acvision

image1477×92 37.2 KB

Checking the 1st model if working

Context:
Could you please refer the similar issues link1 6 and  link2 4
Hope this helps.Thanks


Tensorflow lite model works in python but not in java app for Android

Question:
Hi,
I have successfully converted my tensorflow model from h5 to tflite and was able to use it in python to perform inference on a random test image (see tflite_model_test.ipynb under Colab Notebooks - Google Drive)
I tried to port it to Android Studio (Arctic Fox), loading the model to assets, and attempted two code paths to perform inference and both returned NAN values (see code below). I have been looking for answers in the last few days and couldn’t find anything that would work. I would really appreciate it if someone can let me know what I may have missed.
Code:
    String path = "/storage/emulated/0/Pictures/test_img.png"
    try {
        if (!OpenCVLoader.initDebug())
            Log.e("OpenCV", "Unable to load OpenCV!");
        else
            Log.d("OpenCV", "OpenCV loaded Successfully!");

        // Create inputs for reference.
        TensorBuffer inputFeature = TensorBuffer.createFixedSize(new int[]{1, 256, 256, 1}, DataType.FLOAT32);
        Mat image = Imgcodecs.imread(path);
        Imgproc.cvtColor(image, image, Imgproc.COLOR_RGB2GRAY);
        Imgproc.resize(image, image, new Size(256, 256));

        // Check if the image is loaded properly
        Bitmap testBmp = Bitmap.createBitmap(image.cols(), image.rows(), Bitmap.Config.ARGB_8888);
        Utils.matToBitmap(image, testBmp);

        // normalize first
        image.convertTo(image, CvType.CV_32FC(1));
        Mat dstFrame = new Mat();
        Core.divide(image, new Scalar(255.0), dstFrame);

        // load content of image into inputFeature
        float[] floats = new float[dstFrame.rows() * dstFrame.cols()];
        dstFrame.get(0,0, floats);
        byte[] bytes = floatToByte(floats);
        ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
        inputFeature.loadBuffer(byteBuffer);

        // sanity check to see if retBmp is the same as testBmp, using the Android Studio debug feature,
        // I was able to confirm this was the case, the image also matches the input used in colab
        float[] floats1 = inputFeature.getFloatArray();
        Mat retFrame = new Mat(256, 256, CvType.CV_32FC(1));
        retFrame.put(0, 0, floats1);
        Core.multiply(retFrame, new Scalar(255.0), retFrame);
        Bitmap retBmp = convertMat2Bitmap(retFrame);

        // Method 1: using the default path suggested by sample code in Android Studio for test_model.tflite
        TestModel model = TestModel.newInstance(this);
        TestModel.Outputs outputs = model.process(inputFeature);
        TensorBuffer outputFeature = outputs.getOutputFeature0AsTensorBuffer();
        float[] data = outputFeature.getFloatArray();
        // data is populated with NAN values

        int[] bbox = new int[4];
        for (int i=0; i<4; i++)
            bbox[i] = (int) (data[i] * 256);

        // Releases model resources if no longer used.
        model.close();

        // Method 2: Use Interpreter, and this yields the same result of NAN values
        MappedByteBuffer tfliteModel = FileUtil.loadMappedFile(this, "test_model.tflite");
        Interpreter tflite = new Interpreter(tfliteModel);
        TensorBuffer outputBuffer = TensorBuffer.createFixedSize(new int[]{1, 4}, DataType.FLOAT32);
        Mat retFrame2 = new Mat(256, 256, CvType.CV_32FC(1));
        tflite.run(inputFeature.getBuffer(), outputBuffer.getBuffer());
        float[] data2 = outputBuffer.getFloatArray();
        // data2 is populated with NAN values

        int[] bbox2 = new int[4];
        for (int i=0; i<4; i++)
            bbox2[i] = (int) (data2[i] * 256.0);

        Log.d("The end", "last line of the code");
    } catch (Throwable t) {
        // TODO Handle the exception
        Log.d("ERROR", t.getMessage());
    }

Context:
Hi @George_Zheng
Is it necessary to do that using OpenCV? Do you have restrictions for using that?
Wouldn’t be simpler to load directly the Bitmap from assets folder, resize it and create the ByteBuffer?
Like:

fun loadBitmapFromResources(context: Context, path: String): Bitmap {
val inputStream = context.assets.open(path)
return BitmapFactory.decodeStream(inputStream)
}

var loadedBitmap = loadBitmapFromResources(context, “woman.png”)

val inputBitmap = Bitmap.createScaledBitmap(
loadedBitmap,
width,
height,
true
)

var tensorImage = TensorImage(DataType.FLOAT32)
tensorImage.load(inputBitmap)

…

TensorBuffer outputBuffer = TensorBuffer.createFixedSize(new int[]{1, 4}, DataType.FLOAT32);
tflite.run(tensorImage.getBuffer(), outputBuffer)
val data2 = outputBuffer. getFloatArray()

and log to see the values of data2.
OR if your model contains metadata you can follow the example here where the ML Model Binding does the preprocessing also:

      TensorFlow

Generate model interfaces using metadata  |  TensorFlow Lite

check the generated code for code sample.
Ping me if you need more help


Question:
Hi everyone!
I’m new with Tensorflow and I’m working with a particular representation. I need add external feacture but in the end to model, por example:

input_1 = Input(shape=(train_s1_seq.shape[1],))
input_2 = Input(shape=(train_s2_seq.shape[1],))
input_3 = Input(shape=(dist_text.shape[1],))

I need that input_3 add in the end for concatenation.

common_embed = Embedding(name=“synopsis_embedd”,input_dim =len(t.word_index)+1,
output_dim=len(embeddings_index[“x”]),weights=[embedding_matrix],
input_length=train_s1_seq.shape[1],trainable=False)
lstm_1 = common_embed(input_1)
lstm_2 = common_embed(input_2)

Bi-LSTM

common_lstm = Bidirectional(LSTM(tot_neuronas_lstm, return_sequences=True, activation=“relu”)))
vector_1 = common_lstm(lstm_1)
vector_1 = Flatten()(vector_1)
vector_2 = common_lstm(lstm_2)
vector_2 = Flatten()(vector_2)
I can add vector_1 and vector_2, that come from Embedding and LSTM respectively. The problem is with “Input_3”, I put it directly in concatenate but it gives me the following error:
ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor(type_spec=TensorSpec(shape=(None, 3), dtype=tf.float32, name='input_144'), name='input_144', description="created by layer 'input_144'") at layer "concatenate_47". The following previous layers were accessed without issue: ['synopsis_embedd', 'synopsis_embedd', 'bidirectional_47', 'bidirectional_47', 'flatten_94', 'flatten_95', 'multiply_142', 'multiply_143', 'subtract_94', 'multiply_141', 'subtract_95', 'lambda_47']

Concatenate

conc = Concatenate(axis=-1)([input_3, vector_1, vector_2])
¿Can you me a help for to solve this problem?. I appreciatte very much the help.
Greeting,
CarlosJ.

Context:
You can visualize the graph with tf.keras.utils.plot_model(model, show_shapes=True, show_dtype=True). It could help to find disconnected parts of the graph or errors in the model architecture.
You say that the model has 3 input layers, but the ValueError says about missing values from the layer named “input_144”. It seams that the model has at least 144 input layers.


Spatial coordinates - network architecture

Question:
Hi,
What kind of network architecture is used for input feature with multiple X,Y,Z coorinates(for ex: 4 coordinates (x1,y,z1), (x2,y2,z2),(x3,y3,z3), (x4,y4,z4) ) & few other numeric input features and the target is numeric.
The coordinates are related to spatial information(drone coordinates in xyz plane to be specific). Is there any specific network that preserves the spatial meaning or just a simple regression network is fine?

Context: Can you share a little bit more info about your task?


Spurious dimensionality during evaluation

Question:
Our team has implemented a tf.keras.Model sub-classed model overriding the train_step() method. We also implemented the call() method of the underlying model.
Now, during evaluation (i.e., running inference on what’s passed to validation_data), we observe that a spurious dimension gets added to intermediate values. Like the expected dimension is, say (128, 768) (where 128 denotes the batch size) but we get (128, 128, 768). But when a separate test_step() is implemented this behavior goes away.
Has anyone faced something similar?
Cc: @nilabhra

Context: Do you have a minimized version tto shaee to reproduce this?


TF Serving can’t used two different classifier at the same time

Question:
I want to serve and run a different model at the same time to make a prediction but having an error serving the 2nd model.
My Docker Images

Screenshot from 2021-09-28 13-38-04697×82 14.3 KB

My Container

Screenshot from 2021-09-28 13-38-521633×75 17.5 KB

Testing the TF Serving - It works only on the 1st model.

Context:
@gabbygab1233
Hope these similar issues helps you link1 1 and link2 1.
For more information refer this blog 1
Thanks


Questions about Keras Beginner Tutorial on Basic Image Classification

Question:
Hi,
I have a few very very simple questions. Just started learning how to use TensorFlow, am going through the first beginner tutorial. Can someone explain to me what these two numbers represent:

Number11104×463 65 KB

Number2893×477 52.1 KB

According to the tutorial, there are 70k of images. Are all 60k images used for updating the weights and biases in the neural network at every iteration or is it only 1875? Similarly, are the remaining 10k used for testing or is it 313?
Thanks.

Context:
It’s the number of batches used for training in each epoch. In this case the model is trained on all available train samples every epoch, which total 1875 batches. Then it is evaluated on all test samples, which total 313 batches.
If you divide the number of samples by the batch size, you should get the same numbers .
In this basic example the number of batches just shows the training progress. But there are some use cases, when it could be beneficial to set the “steps_per_epoch” argument in fit() to some smaller number of batches and validate the model more often.


Anyone worked with speech recognition using cnn?

Question:
Hey mates, I was trying to build a speech recognition model in tensorflow. I downloaded the Tensorflow speech recognition dataset from kaggle and using the yamnet pre-trained model , I build spectrograms of the respective audio signals. Problem comes here that I want to convert each spectrogram into a file and add into my directory for train and test and further create a ImageDataGenerator to load the images inside my model. Any ideas how can I convert my spectrogram to an Image file to store it in a directory ??
Thanks .

Context:
Have you checked this:

      TensorFlow

Audio Data Preparation and Augmentation  |  TensorFlow I/O 13


MeanMetricWrapper produces inconsistent results on multiple runs

Question:
Hi, I have noticed an inconsistency where wrapping the metric and passing pure lambda produce different results some of time. Google Colab 3
If you run the last cell multiple times, you will see instances where mean_squared_wrapped and mean_squared_error_fn are not equal to each other.
How can we explain this?
Thanks

Context:
I think you need to fix your colab:
NameError: name 'custom_mean_squared_error' is not defined


How can I access to HDFS file system in the latest Tensorflow 2.6.0?

Question:
I recently upgraded the tensorflow version used in my program to the recently released 2.6.0, but I ran into a trouble.
import tensorflow as tf

pattern = 'hdfs://mypath'
print(tf.io.gfile.glob(pattern))

The above API throws an exception in version 2.6:
tensorflow.python.framework.errors_impl.UnimplementedError: File system scheme'hdfs' not implemented (file:xxxxx)

Then I checked the relevant implementation code 9 and found that the official recommendation is to use tensorflow/io to access hdfs, and the environment variable TF_USE_MODULAR_FILESYSTEM is provided to use legacy access support. Since my code is more complex and difficult to refactor in a short time, I tried to use this environment variable, but it still failed.
In general, my questions are:

In the latest version of tensorflow, if “tfio” is not used, how can I still access the HDFS file?
If “tfio” must be used, what is the equivalent code call to tf.io.gfile.glob?

Context:
You need to import tensorflow_io alongside tensorflow since the 2.6.0 version:
Install with:
pip install tensorflow-io
In your code:
import tensorflow as tf
import tensorflow_io as tfio


Question:
Hallo,
i’m facing a problem with TF and Django.
my code is:
modelSavePathName = os.path.join(data_dir, f'detector_26082021_2111.h5')
detector.model.load_weights(modelSavePathName, by_name=True)
modelSavePathName = os.path.join(data_dir, f'recognizer_27082021_0846.h5')
recognizer.model.load_weights(modelSavePathName, by_name=True)
pipeline = keras_ocr.pipeline.Pipeline(detector=detector, recognizer=recognizer, max_size=4096)
imagesDF = keras_ocr.tools.read(img)
pr = pipeline.recognize(images=[imagesDF ])[0]

when i call pipeline.recognize(images=[imagesDF ])[0] localy it works. but when i call it in Django view i get this error:

ValueError at /
Tensor Tensor(“conv_cls.8_1/BiasAdd:0”, shape=(None, None, None, 2), dtype=float32) is not an element of this graph.
can anyone help me please, I’m desperate.
best regards

Context:
Why you don’t try to serve your model:

      TensorFlow

Serving Models  |  TFX  |  TensorFlow 1


LSTM using pandas 0.25 and tensorflow 1.15

Question:
I have raised an issue in StackOverflow 2 that you can view in detail, but suffice to say I’m receiving an error I can’t make sense of.

KeyError: ‘No key found for either mapped or original key. Mapped Key: []; Original Key: []’

The intermediate goal for now is to simply get the LSTM model to forecast 1 period ahead using the current period’s data (only 1 timestep). I have two independent variables and one dependent variable. I think perhaps my understanding of how batches/timesteps are processed is a little muddy though. Can someone help me with the error and tell me if the summary() of the model makes sense for what I want to achieve?
Code (assume frame is a pandas dataframe that holds all of the variables):
X = frame[['optimal_long_log_return', 'optimal_short_log_return']][:-1]
Y = frame['equilibrium_log_return'].shift(-1)[:-1]
X_train, _X, y_train, _y = train_test_split(X, Y, test_size=0.5, shuffle=False, random_state=1)
X_validation, X_test, y_validation, y_test = train_test_split(_X, _y, test_size=0.5, shuffle=False, random_state=1)

train = TimeseriesGenerator(X_train, y_train, 1, batch_size=batch_size)
validation = TimeseriesGenerator(X_validation, y_validation, 1, batch_size=batch_size)
test = TimeseriesGenerator(X_test, y_test, 1, batch_size=batch_size)

model = Sequential(name='Expected Equilibrium Log Return')
model.add(LSTM(256, name='LSTM', stateful=True, batch_input_shape=(batch_size, 1, X_train.shape[1])))
model.add(Dense(1, name='Output'))
model.compile(loss='logcosh', metrics=['mean_absolute_percentage_error'], optimizer='Adam', sample_weight_mode='temporal')
print(model.summary())
model.fit_generator(train, epochs=10, validation_data=validation, verbose=1)
loss, accuracy = model.evaluate_generator(test, verbose=0)
print(f'Model Accuracy: {accuracy}')

Summary:
Model: "Expected Equilibrium Log Return"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
LSTM (LSTM)                  (32, 256)                 265216
_________________________________________________________________
Output (Dense)               (32, 1)                   257
=================================================================
Total params: 265,473
Trainable params: 265,473
Non-trainable params: 0

Context:
I have created this question in detail on stackoverflow, but as a synopsis:
I want to create an LSTM which will take in a pandas dataframe of independent variables and optimize for the dependent variable. The error I’m receiving is as such:

KeyError: ‘No key found for either mapped or original key. Mapped Key: []; Original Key: []’

Unfortunately I cannot update tensorflow from 1.15 or pandas from 0.25 as the environment I’m developing in doesn’t allow for it. The error occurs in the fit_generator() method.