Cannot prepare a Tensorflow Decision Forests model for Earth Engine

Question:
Hi All,
I want to set up a Tensorflow decision forests model for inference using Google Earth Engine. There is already a Colab notebook example on how to do that using a Neural Network, I’m basically trying to do the same thing but with a random forest model.
However, when I try and prepare the model for “EEification” using the earth engine command line tool, it fails. I’m pretty sure the error is related to the way the earth engine command line tool calls the Tensorflow library but not sure what the solution is.
Example colab notebook with very simple example: Google Colab 4
The notebook requires that you have set up Earth Engine with the Google account that you authenticate with.
Thanks in advance!
Matt

Context:
Sorry for my complete ignorance on earchengine but when you call the cmd line (with the error) what happens? does it creates a VM (or container) and uses that to run the model?
My gut guess says that if it’s that, maybe that VM is missing the TFDF dependency and so lacks the missing ops.
Maybe @Mathieu or @Jan might be have some insight


.so footprint reduction not working (2.6.0)

Question:
Hi. (I already posted similar question on stack overflow, but reposting here for visbility).
I am following instructions here: Reduce TensorFlow Lite binary size 1.
Tensorflow version: 2.6.0, and i am running everything in a devel-cpu docker container as found in tensorflow/tools/dockerfiles (which is, worth noting, ubuntu 18.04 image). Here is my BUILD file:
load(
    "//tensorflow/lite:build_def.bzl",
    "tflite_custom_cc_library",
    "tflite_cc_shared_object",
)

load(
    "//tensorflow/lite/delegates/flex:build_def.bzl",
    "tflite_flex_cc_library",
)

tflite_flex_cc_library(
  name = "selective_cc_flex",
  models = [
     ":saved_model.tflite",
  ],
)

tflite_custom_cc_library(
    name = "selective_cc_builtin",
    models = [
        ":saved_model.tflite",
    ],
)

tflite_cc_shared_object(
    name = "tensorflowlite",
    # Until we have more granular symbol export for the C++ API on Windows,
    # export all symbols.
    features = ["windows_export_all_symbols"],

    linkopts = select({
        "//tensorflow:macos": [
            "-Wl,-exported_symbols_list,$(location //tensorflow/lite:tflite_exported_symbols.lds)",
        ],
        "//tensorflow:windows": [],
        "//conditions:default": [
        "//conditions:default": [
            "-Wl,-z,defs",
            "-Wl,--version-script,$(location //tensorflow/lite:tflite_version_script.lds)",
        ],
    }),
    per_os_targets = True,
    deps = [
        ":selective_cc_builtin",
        "//tensorflow/lite:tflite_exported_symbols.lds",
        "//tensorflow/lite:tflite_version_script.lds",
   #        ":selective_cc_flex",
   #     "//tensorflow/lite/delegates/flex:exported_symbols.lds",
   #     "//tensorflow/lite/delegates/flex:version_script.lds",

    ],
)

Which for convenience includes both built-in and flex selective build in one file, but otherwise is more or less identical to what happens in the instructions. I just change the final dependency if i want to try one or the other.
I tried both with exactly the same outcome: no matter what library i copy for the saved_model.tflite, i get exactly the same tensorflowlite.so binary size.
For example, if I compile for --config=elinux_armhf, built-in operations, I always get a binary of 3,198,770, no matter which model i use for saved_model.tflite. If I use, for example, SPICE model from the same page, i still get this over 3Mb size, whereas the same instruction page advertises at the moment 376kb aar for Android. It is not quite the same, but it would have the jni version of the same .so inside it, which, if I read TF bazel build correctly, more or less follows the same path of operation filtering.
Similarly, if I build for flex (aka SELECT TF) ops, i get north of 200 Mb(!) binaries on x86, whereas advertised size for android is ~1.7kb, give or take. I get similarly gargantuan footprints for elinux_armhf and elinux_aarch64 builds.
What am I doing wrong? Or perhaps my expectations are wrong? If so, then i don’t see a difference between selective build and a regular build.
Thank you.

Context:
I am currently doing a similar thing I might try to compile tommorow. I tried to build natively on windows a week ago with no success, then I put it off for doing other stuff.
Also please look into tensorflow/build_android.md at master · tensorflow/tensorflow (github.com) 7
Will let you know with my results soon.


Create Instructions for user when recording a video

Question:
Greetings,
I am trying to create a portal where users are asked to take a selfie video of themselves; when taking a selfie video I want to instruct user to do certain task to check their liveness (like ask them to turn their head left, and then turn their head right etc.)
These instruction should appear on their device screen (they will read the instruction and follow.
But I am very new to TensorFlow and web app development.
Can anyone help me find relevant resources (YouTube videos etc.)?
Note: I use Python Flask.

Context:
Hello there and welcome to the TensorFlow.JS community!
So for this you may want to look into our MoveNet (body pose - including keypoints on face) and our  FaceMesh models (many more keypoints on head - if that is important) to do what you need.
All of these models run entirely in the web browser so no backend needed - you can use whatever web server you like to serve the HTML/CSS/JS that you write.
Try our MoveNet model here live right now (ensure you allow access to your camera when asked):
https://storage.googleapis.com/tfjs-models/demos/pose-detection/index.html?model=movenet 2
Here is the documentation for our Pose API which includes MoveNet above:

      github.com

tfjs-models/pose-detection at master · tensorflow/tfjs-models 3

  master/pose-detection

  Pretrained models for TensorFlow.js. Contribute to tensorflow/tfjs-models development by creating an account on GitHub.

This movenet model may be good enough for your needs as it contains head keypoints too.
If you need extra granularity around the face try our FaceMesh mode (though it can be a bit more intensive to run - so experiment with both and see what you need):

      github.com

tfjs-models/face-landmarks-detection at master · tensorflow/tfjs-models 3

  master/face-landmarks-detection

  Pretrained models for TensorFlow.js. Contribute to tensorflow/tfjs-models development by creating an account on GitHub.

You can try the demo for FaceMesh here:
https://storage.googleapis.com/tfjs-models/demos/face-landmarks-detection/index.html 4
Happy hacking!


Question:
I was going to install Tensorflow on virtual environment. I installed python=3.7.12 and activated the venv. When I tried to install Tenserflow I get an Error:
>pip install tensorflow
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow

That is an IBM Power8 machine (only CPU). What is the issue and how can I solve it?

Context:
You can find some IBM builds at:

      github.com

GitHub - tensorflow/build: Build-related tools for TensorFlow - TensorFlow Builds 60

  Build-related tools for TensorFlow. Contribute to tensorflow/build development by creating an account on GitHub.


Question:
Hey Community!
We are using the tensorflows js pose tracking technology and have a question.
Are/Is there any libraries/usable existing code out there which can track multiple fitness exercises (squats, pushups, situps, burpees, …)?
We have already programmed some exercises ourselves but as it takes a lot of time and our team was wondering if anybody already did something similar.
If somebody could help us in any way please answer here or contact me via (removed by moderator)

Context:
Welcome to the TensorFlow.JS community great to have you here!
Actually your question is very timely. We have a live interview with the creator of TeamSportz.pro on our TensorFlow.js community show and tell this Friday at 9AM PT. If you can join this stream I highly recommend it as he will also be live in the chat to answer any questions.
Learn more about the company here (they are using TensorFlow.js to do all of this):

      teamsportz.pro

AI sports platform to help every team reach their full potential 3

  We are for every team, coach and player. TeamSportz is an accessible hassle-free sports platform that helps teams, coaches and players come together, track and understand their performance, organise games, communicate with players all from a single...

We also have an example with Include Health that provide remote physiotherapy at scale. Some more details here (check the GIFs toward the end):

      blog.tensorflow.org

Next-Generation Pose Detection with MoveNet and TensorFlow.js 1

  MoveNet is a human pose detection architecture developed at Google that is ultra fast and accurate. It was designed to detect difficult poses

And of course come join the live stream in just a few days time:
TensorFlow.js Community "Show & Tell" #6

We will have 6 new community demos 2 of  which I think may be useful to your use case.


Question: I’m building a segmentation model by following the tutorial 3. Is it possible to create an U-Net that doesn’t output a mask but instead the masked image itself?

Context:
If you want to do this from the model itself you need to use an additional output where you will multiply the original input image with the binarized output mask.
If you don’t need to do this in the model you can do the same as a post-processing step.


How to get confusion matrix and precision of CNN model

Question:
I have trained a CNN with keras to detect if an image has a manhole inside or not. I want to get the confusion matrix and precision recall of my model but i dont know what is my real data and my predicted data.
This is the input I have:
Imports of datasets inside Drive
ds_negatives = np.loadtxt('/content/drive/MyDrive/Colab Notebooks/negative_depth.txt')
ds_positives = np.loadtxt('/content/drive/MyDrive/Colab Notebooks/positive_depth.txt')

#Labeled arrays for datasets
arrayceros = np.zeros(n_negatives_img)
arrayunos = np.ones(n_positives_img)

#Reshaping of datasets to convert separate them
arraynegativos= ds_negatives.reshape(( n_negatives_img, img_height, img_width,1))
arraypositivos= ds_positives.reshape((n_positives_img, img_height, img_width,1))

#Labeling datasets with the arrays
ds_negatives_target = tf.data.Dataset.from_tensor_slices((arraynegativos, arrayceros))
ds_positives_target = tf.data.Dataset.from_tensor_slices((arraypositivos, arrayunos))

#Concatenate 2 datasets and shuffle them
ds_concatenate = ds_negatives_target.concatenate(ds_positives_target)
datasetfinal = ds_concatenate.shuffle(n_total_img)

print("shape of positive data:",datasetfinal)
#24000 images for the training ds and 20000 for the validation ds
valid_ds_f = datasetfinal.take(10000)
train_ds_f = datasetfinal.skip(10000)

valid_ds = valid_ds_f.batch(12)
train_ds = train_ds_f.batch(12)

This is the fit of the model:
history= model.fit(train_ds, validation_data=valid_ds, batch_size=100, epochs=10)

BTW i leave here the link to the code.

      colab.research.google.com

Google Colaboratory

Context:
your real data could be your test split with the labels
the predicted data is what your trained model returns when you give the test split data.
is that it or maybe I didn’t understand the question


Question:
Hi guys,
I’m trying to save my keras model using model.save(/models/test_model.model)
but it keeps saying that tensorflows permission is denied to the dir.
I’ve tried using the .hs5 ext also but doesn’t work.
any help appreciated, thanks

Context: Are you sure you have permission to write where you want to write. I guess you’re on linux you could try touch /models/test_model.testfile this creates an empty file, just to see if that works


Modification of layers in hub.KerasLayer

Question:
hub.KerasLayer object does not allow modification of existing layer parameters. This is debilitating to users who would like to use tfhub models in their own architecture with minor changes. Some specific use cases are mentioned below

Residual networks (2D and 3D) can be dilated appropriately to increase the size of feature maps and they have been known to benefit performance in tasks such as semantic segmentation and image classification such as here 4.
Removing temporal pooling in 3D CNNs. In many applications such as tracking and action detection, it is of interest to remove temporal pooling to keep same number of frames in input and output. This also requires modification of layer parameters.
Access to intermediate activations is also important for explanability issues. This requires accessing intermediate layers which is currently not supported.
Access to intermediate layers is also important to utilize multiple layers of a CNN directly in cases such as FPN and in some object detectors such as MSCNN.

I therefore believe that usability of tfhub models would increase tremendously if hub.KerasLayer object is allowed to be modified. Is there any plan to consider this because it seems pretty important to improve the outreach of tfhub.

Context:
HI @Ujjwal
Thanks for your detailed feedback
Given the structure of SavedModel, I don’t think this request is address-able in general. TF Hub only can expose elements that a publisher decided to provide callable end-points for.
For the modification that you are looking for working directly with code like the ones from Model Garden 2 ( blog post 1 is the way to go.


Question: I really hope someone who could tell me how to avoid the java.nio.BufferOverflowException on Android devices, which happened when calling Interpreter.run(Object input, Object output).

Context:
Hi, welcome to the forum.
Can you provide a few more details? What is the code you are running? What is the model?
Can you create a minimal reproducer that we can then use and identify the issue?


What happened with the Tensorflow Microcontroller Challenge?

Question:
Hi there! Not sure whether this is the right spot to ask … but it seems that people of this forum submitted projects to the Tensorflow Microcontroller Challenge 16, so did I.
The submission deadline was mid of Juli and I’m not aware of any announcements on results or updates. Also the competition terms and everything related to the challenge seem to have been removed from the website (experiments.withgoogle.com 6).
Hence does anyone know what happened with the Tensorflow Microcontroller Challenge or is aware of any updates?
I’m just very curious of the results

Context: @Marcus might have some insights about this


Question:
Hello,
I have this CNN model that works for predicting 7 days ahead, it’s based on a tutorial with some mix of my own older code for visualizing the data. I now need to make it work for 30 days. How do I do that? What steps do I need to take?
Before I post all the code here, I do have it in a Google Colab and anyone that wishes to help can simply be linked to it. I’ll post the code here on request or I’ll PM the link to anyone that would like me to. I don’t know if posting links in the threads is allowed.
Thanks in advance!

Context:
Do you need CNN in your use case?
Have you tried one of the Keras Timeseries colab/tutorial?

      keras.io

Keras documentation: Timeseries


Append() changes the shape of class list?

Question:
I apologise if this is in the wrong place.
I need to append() my test numpy array to my history class list and it changes the shape of history from (30, 72, 7) to (31,). At least that’s what it appears like. Why is this? It, later on, causes a tuple out of range when trying to flatten the data.
Thank you in advance.

Context: Do you have a minimal Colab or a code snippet to reproduce this?


Question:
usage: ipykernel_launcher.py [-h] [--weights WEIGHTS [WEIGHTS ...]]
                             [--source SOURCE]
                             [--img-size IMG_SIZE [IMG_SIZE ...]]
                             [--conf-thres CONF_THRES] [--iou-thres IOU_THRES]
                             [--max-det MAX_DET]
                             [--classes CLASSES [CLASSES ...]]
                             [--agnostic-nms] [--augment] [--name NAME]
                             [--line-thickness LINE_THICKNESS] [--hide-labels]
                             [--hide-conf]
ipykernel_launcher.py: error: unrecognized arguments: -f /root/.local/share/jupyter/runtime/kernel-f644771f-d5c8-41cf-978a-37032aec69fe.json
An exception has occurred, use %tb to see the full traceback.

SystemExit: 2
/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py:2890: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
  warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)

Can someone tell me why I am getting this error?

Context: Who Is passing the -f arg?


Question:
When converting the keras model to tflite the converter infers the output shapes and signatures wrongly. Is there a way I can set the output shapes manually?
FYI it is a segmentation model.
This is what I am getting:
[{‘name’: ‘Identity’, ‘index’: 222, ‘shape’: array([1, 1, 1, 1], dtype=int32), ‘shape_signature’: array([-1, -1, -1,  1], dtype=int32), ‘dtype’: <class ‘numpy.float32’>, ‘quantization’: (0.0, 0), ‘quantization_parameters’: {‘scales’: array([], dtype=float32), ‘zero_points’: array([], dtype=int32), ‘quantized_dimension’: 0}, ‘sparsity_parameters’: {}}]
But I am expecting this:
[{‘name’: ‘Identity’, ‘index’: 103, ‘shape’: array([  1, 256, 256,   1], dtype=int32), ‘shape_signature’: array([ -1, 256, 256,   1], dtype=int32), ‘dtype’: <class ‘numpy.float32’>, ‘quantization’: (0.0, 0), ‘quantization_parameters’: {‘scales’: array([], dtype=float32), ‘zero_points’: array([], dtype=int32), ‘quantized_dimension’: 0}, ‘sparsity_parameters’: {}}]

The model summary:
Layer (type)                    Output Shape         Param #     Connected to
input_2 (InputLayer)            [(None, 256, 256, 3) 0

batch_normalization_32 (BatchNo (None, 256, 256, 3)  12          input_2[0][0]

activation_35 (Activation)      (None, 256, 256, 3)  0           batch_normalization_32[0][0]

conv2d_36 (Conv2D)              (None, 125, 125, 64) 9472        activation_35[0][0]

max_pooling2d_1 (MaxPooling2D)  (None, 63, 63, 64)   0           conv2d_36[0][0]

batch_normalization_33 (BatchNo (None, 63, 63, 64)   256         max_pooling2d_1[0][0]

activation_36 (Activation)      (None, 63, 63, 64)   0           batch_normalization_33[0][0]

conv2d_37 (Conv2D)              (None, 32, 32, 64)   36928       activation_36[0][0]

batch_normalization_34 (BatchNo (None, 32, 32, 64)   256         conv2d_37[0][0]

activation_37 (Activation)      (None, 32, 32, 64)   0           batch_normalization_34[0][0]

conv2d_39 (Conv2D)              (None, 32, 32, 64)   4160        max_pooling2d_1[0][0]

conv2d_38 (Conv2D)              (None, 32, 32, 64)   36928       activation_37[0][0]

add_11 (Add)                    (None, 32, 32, 64)   0           conv2d_39[0][0]
conv2d_38[0][0]

batch_normalization_35 (BatchNo (None, 32, 32, 64)   256         add_11[0][0]

activation_38 (Activation)      (None, 32, 32, 64)   0           batch_normalization_35[0][0]

conv2d_40 (Conv2D)              (None, 32, 32, 64)   36928       activation_38[0][0]

batch_normalization_36 (BatchNo (None, 32, 32, 64)   256         conv2d_40[0][0]

activation_39 (Activation)      (None, 32, 32, 64)   0           batch_normalization_36[0][0]

conv2d_41 (Conv2D)              (None, 32, 32, 64)   36928       activation_39[0][0]

add_12 (Add)                    (None, 32, 32, 64)   0           add_11[0][0]
conv2d_41[0][0]

batch_normalization_37 (BatchNo (None, 32, 32, 64)   256         add_12[0][0]

activation_40 (Activation)      (None, 32, 32, 64)   0           batch_normalization_37[0][0]

conv2d_42 (Conv2D)              (None, 16, 16, 128)  73856       activation_40[0][0]

batch_normalization_38 (BatchNo (None, 16, 16, 128)  512         conv2d_42[0][0]

activation_41 (Activation)      (None, 16, 16, 128)  0           batch_normalization_38[0][0]

conv2d_44 (Conv2D)              (None, 16, 16, 128)  8320        add_12[0][0]

conv2d_43 (Conv2D)              (None, 16, 16, 128)  147584      activation_41[0][0]

add_13 (Add)                    (None, 16, 16, 128)  0           conv2d_44[0][0]
conv2d_43[0][0]

batch_normalization_39 (BatchNo (None, 16, 16, 128)  512         add_13[0][0]

activation_42 (Activation)      (None, 16, 16, 128)  0           batch_normalization_39[0][0]

conv2d_45 (Conv2D)              (None, 16, 16, 128)  147584      activation_42[0][0]

batch_normalization_40 (BatchNo (None, 16, 16, 128)  512         conv2d_45[0][0]

activation_43 (Activation)      (None, 16, 16, 128)  0           batch_normalization_40[0][0]

conv2d_46 (Conv2D)              (None, 16, 16, 128)  147584      activation_43[0][0]

add_14 (Add)                    (None, 16, 16, 128)  0           add_13[0][0]
conv2d_46[0][0]

batch_normalization_41 (BatchNo (None, 16, 16, 128)  512         add_14[0][0]

activation_44 (Activation)      (None, 16, 16, 128)  0           batch_normalization_41[0][0]

conv2d_47 (Conv2D)              (None, 8, 8, 256)    295168      activation_44[0][0]

batch_normalization_42 (BatchNo (None, 8, 8, 256)    1024        conv2d_47[0][0]

activation_45 (Activation)      (None, 8, 8, 256)    0           batch_normalization_42[0][0]

conv2d_49 (Conv2D)              (None, 8, 8, 256)    33024       add_14[0][0]

conv2d_48 (Conv2D)              (None, 8, 8, 256)    590080      activation_45[0][0]

add_15 (Add)                    (None, 8, 8, 256)    0           conv2d_49[0][0]
conv2d_48[0][0]

batch_normalization_43 (BatchNo (None, 8, 8, 256)    1024        add_15[0][0]

activation_46 (Activation)      (None, 8, 8, 256)    0           batch_normalization_43[0][0]

conv2d_50 (Conv2D)              (None, 8, 8, 256)    590080      activation_46[0][0]

batch_normalization_44 (BatchNo (None, 8, 8, 256)    1024        conv2d_50[0][0]

activation_47 (Activation)      (None, 8, 8, 256)    0           batch_normalization_44[0][0]

conv2d_51 (Conv2D)              (None, 8, 8, 256)    590080      activation_47[0][0]

add_16 (Add)                    (None, 8, 8, 256)    0           add_15[0][0]
conv2d_51[0][0]

batch_normalization_45 (BatchNo (None, 8, 8, 256)    1024        add_16[0][0]

activation_48 (Activation)      (None, 8, 8, 256)    0           batch_normalization_45[0][0]

conv2d_52 (Conv2D)              (None, 4, 4, 512)    1180160     activation_48[0][0]

batch_normalization_46 (BatchNo (None, 4, 4, 512)    2048        conv2d_52[0][0]

activation_49 (Activation)      (None, 4, 4, 512)    0           batch_normalization_46[0][0]

conv2d_54 (Conv2D)              (None, 4, 4, 512)    131584      add_16[0][0]

conv2d_53 (Conv2D)              (None, 4, 4, 512)    2359808     activation_49[0][0]

add_17 (Add)                    (None, 4, 4, 512)    0           conv2d_54[0][0]
conv2d_53[0][0]

batch_normalization_47 (BatchNo (None, 4, 4, 512)    2048        add_17[0][0]

activation_50 (Activation)      (None, 4, 4, 512)    0           batch_normalization_47[0][0]

conv2d_55 (Conv2D)              (None, 4, 4, 512)    2359808     activation_50[0][0]

batch_normalization_48 (BatchNo (None, 4, 4, 512)    2048        conv2d_55[0][0]

activation_51 (Activation)      (None, 4, 4, 512)    0           batch_normalization_48[0][0]

conv2d_56 (Conv2D)              (None, 4, 4, 512)    2359808     activation_51[0][0]

add_18 (Add)                    (None, 4, 4, 512)    0           add_17[0][0]
conv2d_56[0][0]

batch_normalization_49 (BatchNo (None, 4, 4, 512)    2048        add_18[0][0]

activation_52 (Activation)      (None, 4, 4, 512)    0           batch_normalization_49[0][0]

conv2d_57 (Conv2D)              (None, 4, 4, 128)    65664       activation_52[0][0]

up_sampling2d_6 (UpSampling2D)  (None, 8, 8, 128)    0           conv2d_57[0][0]

batch_normalization_50 (BatchNo (None, 8, 8, 128)    512         up_sampling2d_6[0][0]

activation_53 (Activation)      (None, 8, 8, 128)    0           batch_normalization_50[0][0]

conv2d_58 (Conv2D)              (None, 8, 8, 128)    147584      activation_53[0][0]

batch_normalization_51 (BatchNo (None, 8, 8, 128)    512         conv2d_58[0][0]

activation_54 (Activation)      (None, 8, 8, 128)    0           batch_normalization_51[0][0]

conv2d_59 (Conv2D)              (None, 8, 8, 256)    33024       activation_54[0][0]

add_19 (Add)                    (None, 8, 8, 256)    0           conv2d_59[0][0]
add_16[0][0]

activation_55 (Activation)      (None, 8, 8, 256)    0           add_19[0][0]

batch_normalization_52 (BatchNo (None, 8, 8, 256)    1024        activation_55[0][0]

activation_56 (Activation)      (None, 8, 8, 256)    0           batch_normalization_52[0][0]

conv2d_60 (Conv2D)              (None, 8, 8, 64)     16448       activation_56[0][0]

up_sampling2d_7 (UpSampling2D)  (None, 16, 16, 64)   0           conv2d_60[0][0]

batch_normalization_53 (BatchNo (None, 16, 16, 64)   256         up_sampling2d_7[0][0]

activation_57 (Activation)      (None, 16, 16, 64)   0           batch_normalization_53[0][0]

conv2d_61 (Conv2D)              (None, 16, 16, 64)   36928       activation_57[0][0]

batch_normalization_54 (BatchNo (None, 16, 16, 64)   256         conv2d_61[0][0]

activation_58 (Activation)      (None, 16, 16, 64)   0           batch_normalization_54[0][0]

conv2d_62 (Conv2D)              (None, 16, 16, 128)  8320        activation_58[0][0]

add_20 (Add)                    (None, 16, 16, 128)  0           conv2d_62[0][0]
add_14[0][0]

activation_59 (Activation)      (None, 16, 16, 128)  0           add_20[0][0]

batch_normalization_55 (BatchNo (None, 16, 16, 128)  512         activation_59[0][0]

activation_60 (Activation)      (None, 16, 16, 128)  0           batch_normalization_55[0][0]

conv2d_63 (Conv2D)              (None, 16, 16, 32)   4128        activation_60[0][0]

up_sampling2d_8 (UpSampling2D)  (None, 32, 32, 32)   0           conv2d_63[0][0]

batch_normalization_56 (BatchNo (None, 32, 32, 32)   128         up_sampling2d_8[0][0]

activation_61 (Activation)      (None, 32, 32, 32)   0           batch_normalization_56[0][0]

conv2d_64 (Conv2D)              (None, 32, 32, 32)   9248        activation_61[0][0]

batch_normalization_57 (BatchNo (None, 32, 32, 32)   128         conv2d_64[0][0]

activation_62 (Activation)      (None, 32, 32, 32)   0           batch_normalization_57[0][0]

conv2d_65 (Conv2D)              (None, 32, 32, 64)   2112        activation_62[0][0]

add_21 (Add)                    (None, 32, 32, 64)   0           conv2d_65[0][0]
add_12[0][0]

activation_63 (Activation)      (None, 32, 32, 64)   0           add_21[0][0]

batch_normalization_58 (BatchNo (None, 32, 32, 64)   256         activation_63[0][0]

activation_64 (Activation)      (None, 32, 32, 64)   0           batch_normalization_58[0][0]

conv2d_66 (Conv2D)              (None, 32, 32, 16)   1040        activation_64[0][0]

up_sampling2d_9 (UpSampling2D)  (None, 64, 64, 16)   0           conv2d_66[0][0]

batch_normalization_59 (BatchNo (None, 64, 64, 16)   64          up_sampling2d_9[0][0]

activation_65 (Activation)      (None, 64, 64, 16)   0           batch_normalization_59[0][0]

conv2d_67 (Conv2D)              (None, 64, 64, 16)   2320        activation_65[0][0]

batch_normalization_60 (BatchNo (None, 64, 64, 16)   64          conv2d_67[0][0]

activation_66 (Activation)      (None, 64, 64, 16)   0           batch_normalization_60[0][0]

conv2d_68 (Conv2D)              (None, 64, 64, 64)   1088        activation_66[0][0]

up_sampling2d_10 (UpSampling2D) (None, 128, 128, 64) 0           conv2d_68[0][0]

batch_normalization_61 (BatchNo (None, 128, 128, 64) 256         up_sampling2d_10[0][0]

activation_67 (Activation)      (None, 128, 128, 64) 0           batch_normalization_61[0][0]

conv2d_69 (Conv2D)              (None, 128, 128, 32) 18464       activation_67[0][0]

batch_normalization_62 (BatchNo (None, 128, 128, 32) 128         conv2d_69[0][0]

activation_68 (Activation)      (None, 128, 128, 32) 0           batch_normalization_62[0][0]

conv2d_70 (Conv2D)              (None, 128, 128, 32) 9248        activation_68[0][0]

up_sampling2d_11 (UpSampling2D) (None, 256, 256, 32) 0           conv2d_70[0][0]

batch_normalization_63 (BatchNo (None, 256, 256, 32) 128         up_sampling2d_11[0][0]

activation_69 (Activation)      (None, 256, 256, 32) 0           batch_normalization_63[0][0]

conv2d_71 (Conv2D)              (None, 256, 256, 1)  129         activation_69[0][0]
Total params: 11,551,469
Trainable params: 11,541,543
Non-trainable params: 9,926

Context:
Hi @Evans_Kiplagat
I think you have to share with us a colab notebook to see the model and the conversion.
Can you do that?
Thanks


Question:
Hi, I’m trying to test my model on the new image but I’m getting errors on json.
Error message:

Source Code

Screenshot from 2021-09-24 15-30-46832×605 52.1 KB

TF Serving Model

Context:
Hi,
The error is “KeyError: predictions”. On this line:
predictions = json_responce.json()["predictions"][0]

To see what keys that response actually has, try:
print( json_responce.json().keys())


Question: I  have trained a segmentation model and the segmentation accuracy is satisfying. The issues am having is that  I can’t get any results in Android TensorFlow Lite model. I also tested the converted in  Python to a certain that the results are similar to the trained Keras model and they are. I followed the segmentation example in the on tflite examples and am just getting a blank segmentation. I thought it is an issue with normalization but I made sure I included it when adding metadata to the model. Is there anyway I can work around it

Context:
Hi @Evans_Kiplagat
What error logs are you getting on the console? Can you provide them?


Tf numpy usage with Keras Functional API

Question:
Hi,
Can we use tf.experimental.numpy with Keras Functional API?
When I create the following code:

inp1 = keras.layers.Input(shape=(1,), name=“inp1”)
inp2 = keras.layers.Input(shape=(1,), name=“inp2”)
out  = tf.experimental.numpy.add(inp1, inp2)
m = keras.Model([inp1, inp2], out)

I get the following error:
Cannot interpret '<KerasTensor: shape=(None, 1) dtype=float32 (created by layer 'inp1')>' as a data type
Whereas when I use out = tf.math.add(inp1, inp2), there is no issue.
What could be the problem please?
PS: The use case that I have is to calculate the mean of a tensor ignoring all nan values. That’s why I was trying to use tf.experimental.numpy.nanmean which gave the same error.
Thanks!
Fadi Badine

Context:
This works if you wrap it in a keras Lambda layer:
def add_numpy(vals):
  x, y = vals
  return tf.experimental.numpy.add(x, y)

inp1 = tf.keras.layers.Input(shape=(1,), name="inp1")
inp2 = tf.keras.layers.Input(shape=(1,), name="inp2")

out = tf.keras.layers.Lambda(add_numpy)((inp1, inp2))

m = tf.keras.Model([inp1, inp2], out)

m([tf.constant(1.), tf.constant(2.)])

AFAIK the result of calling a Keras functional layer is a KerasTensor which I think is just a placeholder tensor with certain type/shape information to propagate to other layers. The NumPy API probably doesn’t recognize that right now, so this workaround defers the NumPy calls so they work on actual objects they can recognize.


Memory Leaks with TensorFlow.js hand gestures

Question:
Hey guys,
In the last months, I’ve used the same HandPose model used by Minko Gechev, software engineer at Google Angular team, in his demo here: Controlling an Angular app with a camera via hand gestures - YouTube 2
and I have integrated the same source code, shared by him on GitHub (https://github.com/mgechev/angular-tfjs-demo 3) in my Angular application with a slight change in order to be able to navigate between the different steps (or order-creation & product-creation processes) instead of “open/close menu & choose a menu-item”.
Here are the dependencies that I’ve added to my project for the hand gestures feature:
@tensorflow-models/handpose: 0.0.7
@tensorflow/tfjs-backend-webgl: 3.7.0
@tensorflow/tfjs-converter: 3.7.0
@tensorflow/tfjs-core: 3.7.0
fingerpose: 0.0.2
But I’ve faced a performance problem: there is a continuous increase of memory consumption throughout using my application (even after the loading of the hand tracking model is completed and started working). I’ve published an article regarding this topic: https://betterprogramming.pub/web-performance-and-tensorflow-js-3db05b1de958?source=friends_link&sk=3dd881c15f43896d947023b402a9375d 7
and video here: How TensorFlow.js Became a Performance Bottleneck for My App - YouTube 4
I’ve taken many Heap Snapshots and noticed that whenever I go to the view of editing an order or product where the hand gestures tracking is present and then come back to the products list view (where there is no hand tracking), the size of the snapshot increases by almost 20 MB as you can see in the attached screenshots.
I’m using MacBook Pro 13", Version: macOS 11.5.2
My app is available online here: https://angular-dynamic-stepper-4a371.web.app 3
The source code is on GitHub here: https://github.com/rakia/ng-dynamic-stepper 5
I appreciate it if you could give me any note that could help me to fix this memory leak. Many thanks!

continuous_increase_heap_snapshot_8-vs-71915×1034 232 KB

continuous_increase_heap_snapshot_14-vs-131921×989 257 KB

Context: Welcome to the forum - let us take a look and get back to you on this. Thank you for sharing the working links and resources for us to check. Most appreciated.


Question:
I am unable to save the training loss in history.history[‘loss’]. Please have alook at my code below.
model = Sequential()
model.add(LSTM(input_shape = (90,1), activation = ‘tanh’, units= 90, return_sequences = True))
model.add(Dropout(0.1))
model.add(LSTM(200))
model.add(Dense(1))               #tanh has been remove as you requested
model.compile(loss=“mse”, optimizer=“adam”)
history = model.fit(train_X, train_y, batch_size=128, epochs=5,validation_split=0.2, shuffle=False)
model.summary()
Epoch 1/5
55/55 [==============================] - 32s 540ms/step - loss: 0.7681 - val_loss: 1.0027
Epoch 2/5
55/55 [==============================] - 29s 528ms/step - loss: 0.7718 - val_loss: 1.0000
Epoch 3/5
55/55 [==============================] - 29s 535ms/step - loss: 0.7718 - val_loss: 0.9999
Epoch 4/5
55/55 [==============================] - 29s 532ms/step - loss: 0.7701 - val_loss: 1.0006
Epoch 5/5
55/55 [==============================] - 28s 506ms/step - loss: 0.7704 - val_loss: 0.9998
history.history[‘loss’]
[0.9976969361305237,
0.9994587898254395,
0.9989796280860901,
0.9978650808334351,
0.9971943497657776]
Why the values is different from the one printed while training? Please look into the issue.

Context:
Hi Yusuff,
Can you please share a notebook with the issue? (if the data can be shared of course, or with any random data that shows the issue)


Question: In the tour of saved model signatures 4, Daniel Ellis explores the function signature serialisation and shares some screenshots of the internals of the protobuf file. I’m familiar with the saved_model_cli, but never seen a tool that visualises the protobuf as such. Is anyone familiar with the tool used in that post?

Context:
Unfortunately that’s an internal tool at Google and isn’t available more widely, as far as I know.  I assume someone has found the need and written an open source tool for visualizing protos, but I haven’t looked around.
One other idea may be to convert the proto to json (modulo format compatibility issues) and then use a json visualization tool.  Firefox has one built in.  I haven’t tried this though.
Truth be told, the tool in that post only handles 20MB files anyway, so it’s not that useful for debugging “real” models.  I frequently find myself having to use less and dig through the text representation of the proto by hand anyway.  I’m not sure about an open source tool to convert protos to text though.  Alas, it looks like the one I use isn’t open source either.  I think it should be trivial to do if you use the proto library for your language of your choice directly though.


Question:
Hi guys,
I’m trying to  download a dataset using this code in Python, from an ML Codelab but it doesn’t work.
!wget --no-check-certificate
https://storage.googleapis.com/laurencemoroney-blog.appspot.com/rps.zip 1
-O /tmp/rps.zip
It just shows as invalid syntax.
I tried installing wget in my env but makes no difference.

Context:
MTelford:

!wget --no-check-certificate
https://storage.googleapis.com/laurencemoroney-blog.appspot.com/rps.zip
-O /tmp/rps.zip

try without the line breakers:
!wget --no-check-certificate https://storage.googleapis.com/laurencemoroney-blog.appspot.com/rps.zip  -O /tmp/rps.zip


Question: How to use ‘ConvLSTM1D’, are there any packages to install?

Context:
Hi @naveen_kumar,
There is only ConvLSTM2D layer 5 in Keras layers API 5 but you combine Conv1D 4 and LSTM 3 as these layers exists.
You can refer to the notebook that uses Conv1D 7 and LSTMs 5 to get an idea of how to combine them.
You will need to install TensorFlow (refer to the official guide 4) or import it directly in Colab Notebooks 2.


Question:
Hi.
I have a dataset of some 150k records with two columns, a column with text in Igbo language and a column with the sentiment of the text (-1=negative, 0=neutral, 1=positive).
From my research, and I’m not sure if I done it well, I saw that using an LSTM (or BiDirectional LSTM) would be my best choice. I followed a few tutorials and this is what I came up with:
def LSTM_model():
    inp = Input(shape=(MAXLEN, ))
    x = Embedding(vocab_size, 20, input_length=MAXLEN, trainable=True)(inp)
    x = Dropout(0.25)(x)
    x = LSTM(512, dropout=0.2, recurrent_dropout=0.2)(x)
    x = Dense(32, activation='relu')(x)
    x = Dropout(0.25)(x)
    x = LSTM(256, dropout=0.2, recurrent_dropout=0.2)(x)
    x = Dense(32, activation='relu')(x)
    x = Dense(3, activation='softmax')(x)
    model = Model(inputs=inp, outputs=x)
    model.compile(loss='sparse_categorical_crossentropy',
                  optimizer='adam',
                  metrics=['sparse_categorical_accuracy'])
    return model

Before that, I tokenized the text, converted to sequence and applied padding. I used the sentiment column as my label column. vocab_size is just the length of the tokenizer word_index + 1. I used Adam optimizer and a sparse_categorical_crossentropy loss (because I have three categories and they are digits). Am I using the correct loss?
Am I on the right track here? This is just a test function, I probably will need more layers etc. but I just wanted to see if this model would fit my use-case (sentiment analysis).

Context:
Hi Callum,
I think you’re in the right direction but I’d suggest you try this tutorial: Text classification with an RNN  |  TensorFlow 3
it will give you some insights and maybe you can even adapt your model a little bit.


Transfer Learning - Could not find matching function from the SavedModel

Question:
Hello everyone,
I’m trying to use transfer learning on my own dataset structured as:
datatset
    healthy
    unhealthy

First, I loaded these images off disk using image_dataset_from_directory 4.
Then, as good practice I split the dataset on train (80%), validation (10%) and test(10%) when developing the model.
batch_size = 32
img_height = 244
img_width = 244

train_ds = tf.keras.preprocessing.image_dataset_from_directory(
  image_path,
  validation_split=0.2,
  subset="training",
  seed=123,
  image_size=(img_height, img_width),
  batch_size=batch_size)

class_names = train_ds.class_names

val_ds = tf.keras.preprocessing.image_dataset_from_directory(
  image_path,
  validation_split=0.2,
  subset="validation",
  seed=123,
  image_size=(img_height, img_width),
  batch_size=batch_size)

val_batches = tf.data.experimental.cardinality(val_ds)
test_dataset = val_ds.take(val_batches // 5)
val_ds = val_ds.skip(val_batches // 5)

Then, when I’m going to train a simple model with Transfer Learning using the datasets we just prepared.
model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/cropnet/feature_vector/cassava_disease_V1/1'),
    tf.keras.layers.Dense(64, activation='relu'),
    tf.keras.layers.Dense(2)
])

model.compile(
    loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
    optimizer=tf.keras.optimizers.Adam(),
    metrics=['accuracy']
)

log_dir = "logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)

model.fit(train_ds, epochs=10, validation_data=val_ds, callbacks=[tensorboard_callback])

I’m getting the below error:

ValueError: Could not find matching function to call loaded from the SavedModel. Got:
Positional arguments (3 total):
* Tensor(“image:0”, shape=(None, 244, 244, 3), dtype=float32)
* False
* 0.99
Keyword arguments: {}
Expected these arguments to match one of the following 4 option(s):

Option 1:
  Positional arguments (3 total):
    * TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name='image')
    * False
    * 0.99
  Keyword arguments: {}

Option 2:
  Positional arguments (3 total):
    * TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name='image')
    * False
    * TensorSpec(shape=(), dtype=tf.float32, name='batch_norm_momentum')
  Keyword arguments: {}

Option 3:
  Positional arguments (3 total):
    * TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name='image')
    * True
    * 0.99
  Keyword arguments: {}

Option 4:
  Positional arguments (3 total):
    * TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name='image')
    * True
    * TensorSpec(shape=(), dtype=tf.float32, name='batch_norm_momentum')
  Keyword arguments: {}

Context: @Yuqi_Li might have an insight on this


Normalization using keras.layers.experimental.preprocessing - exceptionally slow

Question:
Curious to know whether others have same experience as me when using Keras experimental preprocessing layers. I am finding the ‘adapt’ method take an unusually long time to sweep the entire dataset and calculate state information (eg mean and variance).
I create my dataset like so:
ds = tf.data.experimental.CsvDataset(
filenames = data_files, …
Then I simply create the preprocessing layer (outside the model)
layer_norm = tensorflow.keras.layers.experimental.preprocessing.Normalization(axis=-1)
layer_norm.adapt(ds)
The adapt process takes well over a 90 seconds working on a 25 MB file.
Admittedly, my machine isnt high spec, and i and pulling the data files from a remote server. But even still, this feels very slow.

Context: Same here. I am using a TFRecordDataset stored remotely, and the processing times are along the lines of what you mention.


Question:
I was wondering about the differences between using tf.saved_model.save and model.save under the hood. In my experiments, I came across seeing differences for myself when trying to save a subclassed model. It would be helpful if you could shed some light on how and why these two work differently?
PS: I had raised an issue (https://github.com/tensorflow/tensorflow/issues/52128 3) which contains exactly what I tried but this is only about making changes to the docs and not about trying to understand why and how these are different thus this message.

Context:
See

    What's the recommended way to load Tensorflow 2 saved models General Discussion

    I have a general question regarding the Tensorflow 2 API when it comes to use saved models.
The guideline on this post explains how to save and load TF models

I am wondering why in the post the saved model gets loaded like this:
model = tf.keras.models.load_model('saved_model_folder')

Is this way of loading the model equal to
model = tf.saved_model.load('saved_model_folder')

I am asking because I read that the  Keras H5 format is the old format and it is recommended to use the saved model…


Tensorflow 2.5 with GPU device (Python 3.9, Cuda 11.2.2 , Cudnn 8.1.1) Conda environment - Windows 10

Question:
I want to share the procedure to work with your GPU with the new stable version of tensorflow 2.5 in case someone is having problems with the update.
I have noticed an improvement in training time.
According to official information
https://github.com/tensorflow/tensorflow/releases 98
Procedure:

Install Anaconda with Python 3.9
source: https://docs.conda.io/en/latest/miniconda.html 170

Install the latest version of your GPU driver.

Install Cuda Toolkit 11.2.2
source: https://developer.nvidia.com/cuda-toolkit-archive 429

Download Cudnn 8.1.1
source: https://developer.nvidia.com/rdp/cudnn-archive 453

Now just copy the files inside from each Cudnn folder and paste into your Cuda folder, follow this example.
source: https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html#install-windows 109
A. Copy \cuda\bin\cudnn*.dll to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin.
B. Copy \cuda\include\cudnn*.h to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include.
C. Copy \cuda\lib\x64\cudnn*.lib to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\lib\x64.

Go to your environment variables, Under “System Variables” click on “New” and create the CUDA PATH
detail:

Screenshot 2021-05-25 170730752×222 7.18 KB

Create a new conda environment

conda create --name TF-2.5 python=3.9
conda activate TF-2.5

install tensorflow and libraries

pip install tensorflow
pip install tensorflow-datasets
pip install tensorflow-hub
pip install jupyter
pip install numpy
pip install matplotlib
pip install pandas
if you need to use jupyter notebook with the new version of python and tensorflow (very important)
conda install -c conda-forge ipykernel

Register your environment

python -m ipykernel install --user --name TF-2.5 --display-name “Python 3.9 (Tensorflow 2.5)”

Testing your environment

jupyter notebook
detail:

Screenshot 2021-05-25 1727031368×1017 66.7 KB

that’s all works completely fine for me.
Regards.
Ricardo.

Context: Thanks for sharing, Ricardo. Just to confirm, is this Windows 10 21H1 18 or another version of Windows?


Train more object detection models on top of existing model

Question:
Hi,
When I trained a custom model using on top of the prettrained model, SSD mobilenet, why can’t my newly created savedModel be able to detect some of the pretrained objects such as person or car?
I do not know if it is possible to add new object detection model to an existing dataset (inference graph)?  Please advice on how I can do that.  Thank you

Context:
You can add new objects to the dataset but of course you need to train the model again.
Not detecting some objects depends on what you are doing. If you fine tune ssd-mobilenet with flowers only for example, all the other classes that the base model “knows” won’t be recognized anymore as they are not part of the classifier layers anymore (only the flowers are present).


Looking for help with TensorflowJS based midi pattern generation project

Question:
Firstly, here’s a demo video of the original software generating midi drum patterns based on input from another midi or audio file: https://youtu.be/eYUaYzfZUCo 3
To further explain what is happening: A Google research team had several professional drummers come in to play on electronic drum kits that turn their performances into midi files. They then trained a neural network with Tensorflow on over 14 hours of drum midis played by professional drummers. This is what creates such profound results as seen in the above video. And I have used this myself and found that if you repeatedly give it the same input, it will give nearly the same output, only with very slight variations, as I would expect from a real drummer that is improvising.
My overall goal is to create a fork of this software that has Drumify with a model that is trained on my data-set of midi drum files. So far the furthest I’ve gotten is a MatMul error, after following one of the repo contributor’s instructions that he gave me. It was not without many other issues, like being unable to rebuild natively on Windows, and having to do it through the Windows Subsystem for Linux to get as far as I have gotten so far. I will link here to the issue that has more detailed information. This seems like an old, seemingly abandoned project. I just figured I would try this avenue for more assistance since I see a lot of potential in this project when artists can control the output of the plugins through training their models with the data of their choice.
I’m here to have a tool that is useful to other musicians to streamline their creative workflow, without stifling their style of expression. So, anyone that helps, their contribution will be forever made known to the world.
Here is the link to the issue I’ve created on the repo for more detailed information: https://github.com/magenta/magenta-studio/issues/54 4
Thank you for taking the time to read!

Context:
Welcome to the forum @RileyStang! Thank you for your post. Let me ask around to see if I can find any folk who may be able to answer this one.
@lgusm Do you know anyone on the Magenta team on the forum who may know what is going on here?


Question:
I created a model through tensorflow and then converted the same to tensorflow lite.
In My model I require 2 inputs to predict the specific output.
Could you tell whats changes do I need to do in coding for taking two inputs.
The code that I am consider as my base in Hello word project that is:

      github.com

tensorflow/tensorflow/lite/micro/examples/hello_world at master ·... 7

  master/tensorflow/lite/micro/examples/hello_world

  An Open Source Machine Learning Framework for Everyone - tensorflow/tensorflow/lite/micro/examples/hello_world at master · espressif/tensorflow

Context:
Hi @Aditi_Bhalawat
Check below link if this is something that will help you. RunForMultipleInputsOutputs I think is what you need.

      TensorFlow

Interpreter  |  TensorFlow Lite 9


Question:
I am looking for some theoretical calculator on various models and their theoretical performance, so to speak its inference time, for declared theoretical accelerator HW OPs (e.g. TOPs, GFLOPs, etc…). So I am able roughly to estimate what can be a potential inference performance (inf/s).
If there are some calculation guidelines publicly available, ideally for TensorFlow Lite or Tensorflow Micro, please can you please point me?
Thanks.

Context:
You can check this thread

    Calculate Flops in Tensorflow and Pytorch are not equal? General Discussion

    Given the same model, I found that the calculated flops in pytorch and tensorflow are different. I used the keras_flops (keras-flops · PyPI) in tensorflow, and ptflops (ptflops · PyPI) in pytorch to calculate flops. It seems that flops in pytorch are closed to my own calculation by hands. Is that tensorflow has some tricks to speed up the computation so that few flops are measured? My model in tensorflow
d=56
s=12

inp = Input((750 ,750, 1))
x = Conv2D(d, (5,5), padding='same')(inp)
x = PReLU()…


Question:
Hello everybody :), i am currently working on a solution for detecting and measuring the size of a melting pool.
Therefore i have a question:
Is it possible to safe alle the sizes or coordinates of the detection boxes when detecting from a video?
Thank you for helping me out

Context:
That depends on many things.
For example, is the camera on the video always on the same position? Even a slightly change of perspective would change the measuring of any object in the image.
imagine that the zoom of the camera is changed, the measuring will change and for the Object Detection model it doesn’t matter, it will probably return a bigger square but that doesn’t mean that the object is bigger.
Does it makes sense?


Question:
I am using the model maker salad colab and get this error everytime I run the evaluate function on the newly created tflite model.
InvalidArgumentError: required broadcastable shapes [Op:Mul]
Any ideas on what I might be doing wrong?  This error gets worse if I ignore it and continue to the other steps.

Context:
hi @Winton_Cape seems like this your first time in the community.It seems like you issue is same as in this thread InvalidArgumentError: required broadcastable shapes [Op:Mul]  8
You could try running and make sure to use just cpu if you are on google colab because there are issues with GPU currently as mentioned in that thread. And I don’t know if that’s been fixed.
!pip install tensorflow==2.5.0

if you really want to use gpu and are comfortable switching between nightly version (I would recommend this considering you are doing a tutorial part with not trivial dataset), you can just use this
!pip install tflite-model-maker-nightly


Tensorflow.python.framework.errors_impl.notfounderror: Op type not registered ‘NonMaxSuppressionV3’

Question:
Hello Community,
My former collegue trained a TF algoritme and I am running his script and I face the following error:
'tensorflow.python.framework.errors_impl.notfounderror: Op type not registered ‘NonMaxSuppressionV3’
Can anybody help me out with this?
with kind regards,
Tim

Context: Can you share the code?


TensorFlow: AssertionError(“Unresolved object in checkpoint

Question:
I’m following this tutorial:

      TensorFlow

TensorFlow Addons Networks : Sequence-to-Sequence NMT with Attention Mechanism

in which the encoder, decoder and optimiser are “checkpointed”. When I try to restore the checkpoint as follows:
encoder = Encoder(NUM_WORDS, EMBEDDING_DIM, UNITS, BATCH_SIZE)

decoder = Decoder(NUM_WORDS, 431, EMBEDDING_DIM, UNITS, BATCH_SIZE,
                  'luong')

optimiser = tf.keras.optimizers.Adam()

checkpoint = tf.train.Checkpoint(optimiser=optimiser,
                                 encoder=encoder,
                                 decoder=decoder)

checkpoint.restore(tf.train.latest_checkpoint(checkpoint_dirpath)).assert_consumed()

I have the following error:
AssertionError("Unresolved object in checkpoint {}: {}"
AssertionError: Unresolved object in checkpoint (root).optimiser.iter: attributes {
  name: "VARIABLE_VALUE"
  full_name: "Adam/iter"
  checkpoint_key: "optimiser/iter/.ATTRIBUTES/VARIABLE_VALUE"

Without assert_consumed(), I have no error but encoder, decoder and optimiser are empty, and in doing so, not “checkpointed”.
I tried the solution proposed here:

      stackoverflow.com

  TF2.0: Translation model: Error when restoring the saved model: Unresolved object in checkpoint (root).optimizer.iter: attributes 7

  python-3.x, tensorflow, nlp, tensorflow2.0

  asked by

    Hackerds

  on 03:17PM - 08 Oct 19 UTC

without success.
Thank you in advance for your help.

Context:
Hi @woth , are you following the given collab file 7 ? The collab file given runs just fine as I tested and does not output any error on your given code excerpt (shown in the bellow image). Maybe comparing this file with your own code might help.

image1008×150 8.56 KB


Question:
How can we use the pre-trained BlazePose GHUM 3D model to apply transfer learning to the addition of custom set of images because I want to include people using wheelchairs and people using walkers and crutches as well?
Using Tensorflow.js, I’d like to also track the different joints of a simulated 3D human
character displayed on a webpage. As of now, BlazePose GHUM models will not work as they were
only trained on humans.
How can we use transfer learning in this context so that I can train 3D pose detection for virtual human characters displayed on the web page using BlazePose GHUM?
Thanks in advance!

Context: Hi, the pose models are not suitable for transfer learning. If you have a specific data set and use case, you can train your own model.


Question:
output = Conv2D(filters=3, kernel_size=3, padding='same')(input)

and i want something like Conv2D(filters=3, kernel_size=3, padding='same', weights=my_tensor_of_kernel_weights)(input)
how can I set weights and print current weights?

Context: .get_weights() and .set_weights() methods can be applied to any layer. Here is the documentation: The base Layer class 6


What is the correct way to retrieve the value of a specific index of a 3-D tensor?

Question:
Hello.
I am trying to create a custom metric for my sequential model, where it takes two probability distribuitions, y_pred and y_true, and for every [1] in y_true, it sums the value from y_pred in the same index, and returns it normalized.
ex. y_true: [ [0,0,1], [1,0,0] ]
y_pred: [ [0.2,0.2,0.6] , [0.3,0.4,0.3] ]
returned value: 0.45 ((0.6 + 0.3) / 2)
So I created a function, and passed it as the metric for the model. It did not work, as I could not convert the tensors to numpy, because the function was being converted into a graph function.
Then I wrapped it in a tf.py_function(), which is wrapped in a lambda, and passed it. Now
it seems to be retrieving the correct values, but I do not know how to use the slice() function correctly.
Before, I was getting an error, which told me that it was expecting a certain size for slice, and it was too big.
I changed it, so now slice works. But now it tells me there are multiple values inside the sliced tensor, so it cannot retrieve the true value.
In a 3-D tensor, with shape [1,3,7], when slicing to get a single value from it, what is the correct size for it?
Currently my function looks like this:
def forgivingAccuracy(y_true, y_pred):
    """y_pred and y_true are both 2D vectors in a categorical format, with shape [3,7]

    Both represents 3 mood scores, that ranges from 1 to 7, but

    y_pred is a probability distribuition.

    returns the sum of probabilities guessed correctly, normalized.

    e.g. 3 is the correct score, and it predicts with 0.3 certainty, 0.3 is added.

    then the sum is divided to normalize."""

    correct = float(0)

    total = 3

    row = 0

    """Loops through all scores, adds together the chances predicted correctly.

    e.g. Correct is "Good", and AI predicted it with 60% certainty,

    0.6 is added to the "correct" variable.

    Then, it is divided by the total probability (1 * 3)."""

    for mood in y_true:

        column = 0

        for score in mood:

            #Ugly code, but what it does is slice the tensor to get index [row][column]

            #And then access the content

            #Here is the bug. What is the correct size for this to return a single float?
            target = tf.slice(y_pred,begin=[0,row,column],size=[0,0,1])

            print("target is:")

            tf.print(target)

            if score == float(1) and score.size > 0:

                correct = correct + score.eval()

        row = row + 1

        print("row is: %x" %row)

    return correct / total

Thank you in advance. If there is any other information I need to post, tell me and I will add it as soon as possible.

Context:
I just found the answer. There were two problems.

I was misunderstanding the shape of y_true and y_pred. It is [Batch_size,(Input_shape)].
Which means the shapes were not [3,7], but rather [32,3,7].

The size is supposed to be [1,1,1]. The reason I was getting an error for doing this before is unknown.

I did not know that custom metrics become a tf.function, but after I discovered that all I had to do was
tf.config.run_functions_eagerly(True) to debug this.
I hope this helps anybody running into the same problem.


ValueError: No gradients provided for any input

Question:
I’ve tried to run my model - the UDP check is irrelevant now in the function call. This model takes 100 steps and 2 features per sample - hence the (100, 2) input shape.
class KnownDetector(Model):
    def __init__(self):
        super(KnownDetector, self).__init__()
        self.TCP = tf.keras.Sequential([
            layers.Conv1D(filters=32, kernel_size=3, activation="relu", input_shape=(100, 2)),  # 100 packets, 2 features
            layers.MaxPool1D(pool_size=3, padding='same'),
            layers.Conv1D(filters=32, kernel_size=3, activation="relu"),  # 100 packets, 2 features
            layers.MaxPool1D(pool_size=3, padding='same'),
            layers.Conv1D(filters=32, kernel_size=3, activation="relu"),  # 100 packets, 2 features
            layers.Dense(128),
            tf.keras.layers.Softmax()
        ])

    def call(self, x):
        flag = True  # check if x is TCP or UDP in the future
        if flag:
            return self.TCP(x)

fx = KnownDetector()
fx.compile()
fx.fit(train, train_labels, epochs=1, validation_data=(test, test_labels), batch_size=32)

However, I keep getting this error:

I’ve looked online and it seems like many of the solved issues aren’t relevant to me. Why does this happen and how do I fix it?

Context: In a .compile() method you did not specify optimizer and loss function. Loss is required to calculate gradients.


What is the current dev status for Model parallel in tf.distribute.strategy

Question:
I’ve seen the talk called Inside TensorFlow: tf.distribute.Strategy, it’s in 2019.
Back to that time, TF teams has added the model parallelism ability in their TODO list, and now, it’s at the late Q3 of 2021, what is the dev progress? Is their any general progress of how to easily design a model parallel strategy using TF?

Context:
Do you want an udpate  on

      github.com/tensorflow/tensorflow

      Support model parallelism in tf.distribute.Strategy 4

        opened

        Apr 11, 2019

          guptapriya

        type:feature
        comp:dist-strat

    Current tf.distribute.Strategy only supports data parallelism. We would like to …support the following form of model parallelism: user specifies a number of "logical devices" per replica upfront, and then explicitly places ops on a specific logical device.


Question:
Dears,
Is there an available package of TensorFlow ver.2.6 with GPU support for the Anaconda envirment?
https://anaconda.org/anaconda/tensorflow 8 here available does not have GPU support.
Thanks.

Context:
As it is supported as third party you need to upvote and subscribe:

      github.com/ContinuumIO/anaconda-issues

      Update Tensorflow-GPU for Linux 8

        opened

        Sep 7, 2021

          EkicierNico

    ## Package Information
```
Name: Tensorflow-gpu 2.4.1
Source: Anaconda
Platf…orm: Linux (Ubuntu 18.04 LTS)
```

## Is your update request related to a problem? Please describe.
```
There is an issue with Tensorflow 2.4 about GPU NVIDIA RTX 30XX (RTX 3060 in our case).
The GPU is extremely slow, sometime the initialization is not possible and results are not relevant.

To solve the problem, we had to install the nightly version of Tensorflow (2.7) from PIP, and it works fine.
However, it's not a good way because we mix conda and pip manager.
```

## Describe the solution you'd like
```
Update Tensorflow to 2.5 or 2.6 if it's possible.
Thanks !
```


Distribute Strategy with Keras Custom Loops

Question:
I posted this question on Stack Overflow last week, but it didn’t get any engagement, so I’m hoping that posting here will help me connect with someone who can answer my questions.

      stackoverflow.com

  Distribute strategy scopes with keras custom loops 1

  python, tensorflow, keras

  asked by

    Dan

  on 11:02PM - 10 Sep 21 UTC

I am working with distribute strategy scopes using custom training loops with Keras models. Consider this script which closely follows this tutorial: Custom training with tf.distribute.Strategy  |  TensorFlow Core
import os

import numpy as np
import tensorflow as tf

print(tf.__version__)

fashion_mnist = tf.keras.datasets.fashion_mnist

(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()

# Adding a dimension to the array -> new shape == (28, 28, 1)
# We are doing this because the first layer in our model is a convolutional
# layer and it requires a 4D input (batch_size, height, width, channels).
# batch_size dimension will be added later on.
train_images = train_images[..., None]
test_images = test_images[..., None]

# Getting the images in [0, 1] range.
train_images = train_images / np.float32(255)
test_images = test_images / np.float32(255)

CREATE_MODEL_WITH_SCOPE = False
CREATE_MODEL_SEQUENTIAL = True

input_image = np.random.random((28, 28, 1))
target_image = np.random.random((28, 28, 1))

def data_generator():
    while True:
        yield input_image, target_image

# If the list of devices is not specified in the
# `tf.distribute.MirroredStrategy` constructor, it will be auto-detected.
strategy = tf.distribute.MirroredStrategy()

print('Number of devices: {}'.format(strategy.num_replicas_in_sync))

BUFFER_SIZE = 60000  # len(train_images)

BATCH_SIZE_PER_REPLICA = 64
GLOBAL_BATCH_SIZE = BATCH_SIZE_PER_REPLICA * strategy.num_replicas_in_sync

EPOCHS = 10

train_dataset = tf.data.Dataset.from_tensor_slices((train_images, train_labels)).shuffle(BUFFER_SIZE).batch(
    GLOBAL_BATCH_SIZE)
test_dataset = tf.data.Dataset.from_tensor_slices((test_images, test_labels)).batch(GLOBAL_BATCH_SIZE)

train_dist_dataset = strategy.experimental_distribute_dataset(train_dataset)
test_dist_dataset = strategy.experimental_distribute_dataset(test_dataset)

# Create a checkpoint directory to store the checkpoints.
checkpoint_dir = './training_checkpoints'
checkpoint_prefix = os.path.join(checkpoint_dir, "ckpt")

class MyTask:
    def __init__(self, strategy):
        self.strategy = strategy
        with self.strategy.scope():
            # Set reduction to `none` so we can do the reduction afterwards and divide by
            # global batch size.
            self.loss_object = tf.keras.losses.SparseCategoricalCrossentropy(
              from_logits=True,
              reduction=tf.keras.losses.Reduction.NONE
            )

        with self.strategy.scope():
            self.test_loss = tf.keras.metrics.Mean(name='test_loss')
            self.train_accuracy = tf.keras.metrics.SparseCategoricalAccuracy(
                name='train_accuracy')
            self.test_accuracy = tf.keras.metrics.SparseCategoricalAccuracy(
                name='test_accuracy')

        # model, optimizer, and checkpoint must be created under `strategy.scope`.
        if CREATE_MODEL_WITH_SCOPE:
            with self.strategy.scope():
                self.model = self.create_model()
        else:
            self.model = self.create_model()
        with self.strategy.scope():
            self.optimizer = tf.keras.optimizers.Adam()
            self.checkpoint = tf.train.Checkpoint(optimizer=self.optimizer, model=self.model)

        self.discriminator = self.create_model()

    def create_model(self):
        input = tf.keras.Input(
            shape=(28, 28, 1),
            name="input"
        )
        layers = tf.keras.Sequential([
            tf.keras.layers.Conv2D(32, 3, activation='relu'),
            tf.keras.layers.MaxPooling2D(),
            tf.keras.layers.Conv2D(64, 3, activation='relu'),
            tf.keras.layers.MaxPooling2D(),
            tf.keras.layers.Flatten(),
            tf.keras.layers.Dense(64, activation='relu'),
            tf.keras.layers.Dense(10)
        ])
        if CREATE_MODEL_SEQUENTIAL:
            return layers
        output = layers(input)
        model = tf.keras.Model(
            inputs=input,
            outputs=output
        )
        return model

    def create_model_sequential(self):
        model = tf.keras.Sequential([
            tf.keras.layers.Conv2D(32, 3, activation='relu'),
            tf.keras.layers.MaxPooling2D(),
            tf.keras.layers.Conv2D(64, 3, activation='relu'),
            tf.keras.layers.MaxPooling2D(),
            tf.keras.layers.Flatten(),
            tf.keras.layers.Dense(64, activation='relu'),
            tf.keras.layers.Dense(10)
        ])
        return model

    def train_step(self, inputs):
        images, labels = inputs

        with tf.GradientTape() as tape:
            predictions = self.model(images, training=True)
            loss = self.compute_loss(labels, predictions)
        gradients = tape.gradient(loss, self.model.trainable_variables)
        assert len(gradients) == len(self.model.trainable_variables)
        self.optimizer.apply_gradients(zip(gradients, self.model.trainable_variables))

        # train_accuracy.update_state(labels, predictions)
        return loss

    def compute_loss(self, labels, predictions):
        per_example_loss = self.loss_object(labels, predictions)
        return tf.nn.compute_average_loss(per_example_loss, global_batch_size=GLOBAL_BATCH_SIZE)

    def test_step(self, inputs):
        images, labels = inputs

        predictions = self.model(images, training=False)
        t_loss = self.loss_object(labels, predictions)

        self.test_loss.update_state(t_loss)
        self.test_accuracy.update_state(labels, predictions)

    # `run` replicates the provided computation and runs it
    # with the distributed input.
    @tf.function
    def distributed_train_step(self, dataset_inputs):
        per_replica_losses = strategy.run(self.train_step, args=(dataset_inputs,))
        reduced_losses = strategy.reduce(tf.distribute.ReduceOp.SUM, per_replica_losses, axis=None)
        return reduced_losses

    @tf.function
    def distributed_test_step(self, dataset_inputs):
        return strategy.run(self.test_step, args=(dataset_inputs,))

    def fit(self):
        for epoch in range(EPOCHS):
            # TRAIN LOOP
            total_loss = 0
            num_batches = 0
            for x in train_dist_dataset:
                new_loss = self.train_step(x)
                total_loss += new_loss
                num_batches += 1
            train_loss = total_loss / num_batches

            # TEST LOOP
            for x in test_dist_dataset:
                self.distributed_test_step(x)

            if epoch % 2 == 0:
                self.checkpoint.save(checkpoint_prefix)

            template = ("Epoch {}, Loss: {}, Accuracy: {}, Test Loss: {}, "
                        "Test Accuracy: {}")
            print(template.format(epoch + 1, train_loss,
                                  self.train_accuracy.result() * 100, self.test_loss.result(),
                                  self.test_accuracy.result() * 100))

            # template = ("Epoch {}, Loss: {}")
            # print (template.format(epoch+1, train_loss['loss1']))

            self.test_loss.reset_states()
            self.train_accuracy.reset_states()
            self.test_accuracy.reset_states()

task = MyTask(strategy)
task.fit()

eval_accuracy = tf.keras.metrics.SparseCategoricalAccuracy(
    name='eval_accuracy')

new_model = task.create_model()
new_optimizer = tf.keras.optimizers.Adam()

test_dataset = tf.data.Dataset.from_tensor_slices((test_images, test_labels)).batch(GLOBAL_BATCH_SIZE)

@tf.function
def eval_step(images, labels):
    predictions = new_model(images, training=False)
    eval_accuracy(labels, predictions)

checkpoint = tf.train.Checkpoint(optimizer=new_optimizer, model=new_model)
checkpoint.restore(tf.train.latest_checkpoint(checkpoint_dir))

for images, labels in test_dataset:
    eval_step(images, labels)

print('Accuracy after restoring the saved model without strategy: {}'.format(
    eval_accuracy.result() * 100))

There are two flags in this script that control the behaviour:

CREATE_MODEL_WITH_SCOPE controls whether the model is created under a with strategy.scope():. If this flag is false, no explicit scope is used when creating the model.
CREATE_MODEL_SEQUENTIAL controls whether the model is a keras.Sequential model. If this flag is False, the model is wrapped with the Keras functional API, but it is otherwise the same model

Depending on the combination of flags that I use and the tensorflow environment, this script either works or produces an error such as this one:
Traceback (most recent call last):
  File "scratches/scratch_85.py", line 194, in <module>
    task.fit()
  File "scratches/scratch_85.py", line 168, in fit
    new_loss = self.train_step(x)
  File "scratches/scratch_85.py", line 132, in train_step
    self.optimizer.apply_gradients(zip(gradients, self.model.trainable_variables))
  File "anaconda3/envs/tf_2.4/lib/python3.8/site-packages/tensorflow/python/keras/optimizer_v2/optimizer_v2.py", line 604, in apply_gradients
    self._create_all_weights(var_list)
  File "anaconda3/envs/tf_2.4/lib/python3.8/site-packages/tensorflow/python/keras/optimizer_v2/optimizer_v2.py", line 783, in _create_all_weights
    self._create_slots(var_list)
  File "anaconda3/envs/tf_2.4/lib/python3.8/site-packages/tensorflow/python/keras/optimizer_v2/adam.py", line 127, in _create_slots
    self.add_slot(var, 'm')
  File "anaconda3/envs/tf_2.4/lib/python3.8/site-packages/tensorflow/python/keras/optimizer_v2/optimizer_v2.py", line 838, in add_slot
    raise ValueError(
ValueError: Trying to create optimizer slot variable under the scope for tf.distribute.Strategy (<tensorflow.python.distribute.distribute_lib._DefaultDistributionStrategy object at 0x7f597f1eadc0>), which is different from the scope used for the original variable (MirroredVariable:{
  0: <tf.Variable 'conv2d/kernel:0' shape=(3, 3, 1, 32) dtype=float32, numpy=
array(...)
}). Make sure the slot variables are created under the same strategy scope. This may happen if you're restoring from a checkpoint outside the scope

The expected output from the script looks like this:
Epoch 1, Loss: 0.5163882374763489, Accuracy: 0.0, Test Loss: 0.4203348755836487, Test Accuracy: 85.15999603271484
Epoch 2, Loss: 0.342644065618515, Accuracy: 0.0, Test Loss: 0.36492371559143066, Test Accuracy: 86.51000213623047
Epoch 3, Loss: 0.2957099378108978, Accuracy: 0.0, Test Loss: 0.30147236585617065, Test Accuracy: 89.18000030517578
Epoch 4, Loss: 0.2637444734573364, Accuracy: 0.0, Test Loss: 0.2926381230354309, Test Accuracy: 89.77000427246094
Epoch 5, Loss: 0.24089021980762482, Accuracy: 0.0, Test Loss: 0.2793895900249481, Test Accuracy: 90.36000061035156
Epoch 6, Loss: 0.221912682056427, Accuracy: 0.0, Test Loss: 0.26250553131103516, Test Accuracy: 90.30999755859375
Epoch 7, Loss: 0.20427824556827545, Accuracy: 0.0, Test Loss: 0.2791960835456848, Test Accuracy: 90.05000305175781
Epoch 8, Loss: 0.18922416865825653, Accuracy: 0.0, Test Loss: 0.24758891761302948, Test Accuracy: 91.23999786376953
Epoch 9, Loss: 0.17512068152427673, Accuracy: 0.0, Test Loss: 0.24345894157886505, Test Accuracy: 91.27999877929688
Epoch 10, Loss: 0.16123878955841064, Accuracy: 0.0, Test Loss: 0.23703424632549286, Test Accuracy: 91.55999755859375
Accuracy after restoring the saved model without strategy: 91.27999877929688

Here’s what I’ve observed on two different environments:

tf_2.4 = Tensorflow 2.4.1, python 3.8, CUDA 10.1.243

tf_2.5 = Tensorflow 2.5.0, python 3.8, CUDA 11.2.2

CREATE_MODEL_WITH_SCOPE=False, CREATE_MODEL_SEQUENTIAL=False

tf_2.4: Works correctly
tf_2.5: ValueError: Trying to create optimizer slot variable under the scope…

CREATE_MODEL_WITH_SCOPE=True, CREATE_MODEL_SEQUENTIAL=False

tf_2.4: ValueError: Trying to create optimizer slot variable under the scope
tf_2.5: Works correctly

CREATE_MODEL_WITH_SCOPE=True, CREATE_MODEL_SEQUENTIAL=True

tf_2.4: Works correctly
tf_2.5: ValueError: Trying to create optimizer slot variable under the scope

CREATE_MODEL_WITH_SCOPE=False, CREATE_MODEL_SEQUENTIAL=True

tf_2.4: Works correctly
tf_2.5: ValueError: Trying to create optimizer slot variable under the scope

From the documentation, I think that CREATE_MODEL_WITH_SCOPE should be True. But, I would like to understand what is going on in the various cases. When are the slot variables being created, and how can I make sure they have the proper scope? Why is there a different behaviour between the Sequential and Functional versions of the same model? Why do these two versions of tensorflow produce opposite results on these tests?
Any help in understanding these questions would be greatly appreciated. This question arose because I want to use a custom loop with a more complicated Keras Functional API model, but I encounter this slot variable error and I don’t know how to work around it. I can’t figure out how to manage the scopes and there’s no way to replace the model with a Sequential one.

Context: @lgusm Do we have subscribers to the distributed-training tag?


Is there an existing tokenizer model for Chinese to English translation?

Question:
I am following this tutorial for the transformer model:

      TensorFlow

Transformer model for language understanding  |  Text  | ... 4

I want to try Chinese to English translation, so I had this configuration:
        config = tfds.translate.wmt.WmtConfig(
            description="WMT 2019 translation task dataset.",
            version="0.0.3",
            language_pair=("zh", "en"),
            subsets={
                tfds.Split.TRAIN: ["newscommentary_v13"],
                tfds.Split.VALIDATION: ["newsdev2017"],
            }
        )

builder = tfds.builder("wmt_translate", config=config)

In the pt-en translation tutorial, it seems it has already had a corresponding tokenizer model that can be downloaded:
model_name = "ted_hrlr_translate_pt_en_converter"tf.keras.utils.get_file(    f"{model_name}.zip",    f"https://storage.googleapis.com/download.tensorflow.org/models/{model_name}.zip",    cache_dir='.', cache_subdir='', extract=True)

Is there a tokenizer similar to ted_hrlr_translate_pt_en_converter that can be used directly for Chinese to English translation? Because I want to reuse the code in the tutorial like the following:
def tokenize_pairs(pt, en):

    pt = tokenizers.pt.tokenize(pt)
    # Convert from ragged to dense, padding with zeros.
    pt = pt.to_tensor()

    en = tokenizers.en.tokenize(en)
    # Convert from ragged to dense, padding with zeros.
    en = en.to_tensor()
    return pt, en

Context:
Martin:

pt = tokenizers.pt.tokenize(pt)

In the tokenize_pairs, ‘pt’ is a Tensor. A tokenizer usually takes a string object and return a list.  Why does this tokenizers.pt.tokenize() takes a tensor as input? How to make such a tokenizer to work with this tutorial? I imported the transformers tokenizer but it didn’t work, because it complains about the Tensor as tokenize input:
from transformers import BertTokenizer
tokenizer_en = BertTokenizer.from_pretrained("bert-base-cased")
tokenizer_zh = BertTokenizer.from_pretrained("bert-base-chinese")

def tokenize_pairs(zh, en):
    zh = tokenizer_zh.tokenize(zh)
    # Convert from ragged to dense, padding with zeros.
    zh = zh.to_tensor()
    en = tokenizer_en.tokenize(en)
    # Convert from ragged to dense, padding with zeros.
    en = en.to_tensor()
    return zh, en

BUFFER_SIZE = 20000
BATCH_SIZE = 64
def make_batches(ds):
  return (
      ds
      .cache()
      .shuffle(BUFFER_SIZE)
      .batch(BATCH_SIZE)
      .map(tokenize_pairs, num_parallel_calls=tf.data.experimental.AUTOTUNE)
      .prefetch(tf.data.experimental.AUTOTUNE))

train_batches = make_batches(train_examples)
val_batches = make_batches(val_examples)

So the question is how to adapt the transformer pretrained tokenizers to work with tutorial?


Getting this error Unknown: UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7fe286131e90>

Question:
Hi,
Can someone please help me with this error.
Unknown: UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7fe286131e90>
I checked few stackoverflow links.

      stackoverflow.com

  PIL open() method not working with BytesIO 107

  python, python-imaging-library, pillow

  asked by

    Natecat

  on 11:34PM - 10 May 14 UTC

But seems in keras it is used internally
Below is the colab notebook for reproducibilty

      colab.research.google.com

Google Colaboratory 76

Thanks and Regards,
Subho

Context: @Subhobrata_Mukharjee I ran your note book after some debugging seems like there is issue with some of your image files encodings. I didn’t debug enough to figure out which ones but that should be a clue. PIL seems to throw that error in between training so, that’s another point towards image encoding errors.


Question:
Code: model = image_classifier.create(train_data, validation_data=validation_data, epochs= 10, learning_rate= 0.001, model_spec=model_spec.get(‘mobilenet_v2’))
OSError: SavedModel file does not exist at: C:\Users\Hagen\AppData\Local\Temp\tfhub_modules\145bb06ec3b59b08fb564ab752bd5aa222bfb50a{saved_model.pbtxt|saved_model.pb}
I hope you can help me

Context:
Are the files present on that folder?
During the create method, model maker will use TensorFlow Hub to download the base model (in your case mobilenet_v2) to do transfer learning. Apparently, it thinks the model is there but it can find when loading.
you can also try this code snippet to see if this works fine on your machine:
import tensorflow as tf
import tensorflow_hub as hub
model = hub.load("https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4")

this is basically what Model Maker is doing when you get that error.


Question:
Hi,
Not sure if this is the right place but… I’m trying to convert MoveNet (TensorFlow Hub) to CoreML but I’m finding it impossible. Following instructions from CoreMLTools (TensorFlow 2 Conversion 2) but no success. Any help or guidance?
Thanks in advance.

Context:
I think it might be easier to find help for this specifically on the CoreML forum.
Are you trying to run the model on an iOS device? can’t you run using TFLite interpreter 1? I don’t think that would need the conversion and maybe the CoreML delegate 1 might help with the performance


Is there a way to convert tensorflow model to pytorch?

Question:
I’m trying to understand how to rewrite a model architecture from tensorflow to pytorch and other way around
are there any automatic tools for that?
I only managed to convert tensorflow to onnx, but wasn’t able to convert it further from onnx to pytoch

Context:
Hi,
I think you could ask this in the pytorch forum:

      PyTorch Forums

PyTorch Forums 71

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


Contribution to the open source projects for Beginners

Question:
Hello everyone,
I am new to this community. I’ve a very basic knowledge of JAVA and C programming language and I want to contribute to the open source projects and help the community to grow. Can anyone please guide me what are the things  I should know/learn before contributing to the open source projects.
Thank You

Context:
hi Kanishk
welcome to the TensorFlow Forum
To contribute to the TensorFlow Open Source project you can follow this guide here: Contribute to TensorFlow 9


TFlite model maker train_data.size not working

Question:
I want to know the numbers of my training, test, and validation samples after splitting, but I receive this kind of error.
Code: print(‘Number of Training Samples: {}’.format(train_data.size))
" AttributeError : ‘ImageClassifierDataLoader’ object has no attribute ‘size’

Context:
Hi Hagen,
The ImageClassifierDataLoader 2 creates a tf.data.Dataset. This structures are lazily evaluated so they don’t load everything to memory until you use them, that’s why they don’t have a size atribute
When you use the from_folder method from the dataloader, it will print how many files it found and will be used later, would that help?


Images for Tensorflow Lite Object Detection Model Maker (transfer learning)

Question: I wanted to create a system that can identify rubber ducks using the Tensorflow Lite Object Detection model maker that was originally used to create a salad detector in the YouTube tutorials.  When I used images taken on my phone (Full resolution on a Samsung Galaxy S21 Ultra is 1440 x 3200 pixels and a 20:9 aspect ratio), the system will get a 0.0 testing accuracy.  But when I used photos of rubber ducks from the internet, the system worked find and got a 99% accuracy in testing.  I used the same amount of photos (roughly 400), 50 epochs, and changed the Batch Size on the phone photos ranging from 8 to 24.  Is there a limit to the size of the photos that Tensorflow Lite can train on?  I also tried taking 4:3 aspect ratio photos from my phone, and this didn’t work either.

Context:
Hi,
did you follow this guide: Object Detection with TensorFlow Lite Model Maker 9
?
One problem that might happen on your images is that they are too big and when the tool tries to crop it for the proper input size it removes by mistake the ducks from it (that my random guess)
On the tutorial I mentined there’s a specific link on preparing your own data and that might give you some insights on how to fix this.
hope it helps


Question: I am training a model with early stop, and everytime i run the model it stops at different epochs and different accuracy. So is there a way to obtain same resullts.

Context:
Check:

      keras.io

Keras documentation: Keras FAQ 2


Question:
This summer I had the pleasure to (co-)mentor at Google Summer of Code for TensorFlow. I was responsible for mentoring two students: Aditya and Vasudev.
They implemented and trained SOTA models for image recognition and speech and published them on TensorFlow Hub. We now have RegNets 4 (for vision) and wav2vec2 1 (for speech) with clean training code and pre-trained models open-sourced all in TensorFlow and Keras. Cc: @fchollet.
I had a chance to author this blog post with another fellow mentor Morgan Roff of Google. If you’re a university student and would want to contribute SoTA models in an open-source spirit, do check it out.

      blog.tensorflow.org

TensorFlow Hub’s Experience with Google Summer of Code 2021

  Learn about the fantastic work done by Google Summer of Code students on TensorFlow Hub, and check out models and tutorials for RegNets and Wav2Vec2.

Context:
Great work from the mentors and the students!!!
congrats!!!


I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:185] None of the MLIR Optimization Passes are enabled (registered 2)

Question:
I’m trying to run a voila notebook on my local machine it gives me the error above although I developed the code on Google Colab and works well even in jupyter notebook the code running without problems the only problem is when I render the code using /voila/render the code not working

Screenshot from 2021-09-20 10-00-371356×310 15.5 KB

Context:
Check:

    None of the MLIR Optimization passes are enabled General Discussion

    None of the MLIR Optimization Passes are enabled is a bit misleading as it refers to very particular workflow. But it is benign and has no effect - it just means a user didn’t opt in to a specific pass (which is not enabled by default), so it doesn’t indicate any error and was rather used as signal for developers. But seeing this, it is causing more confusion. I’ll go and update the message.


Load tfrecord dataset from google drive when using TPU in colab

Question:
I am using TPU runtime in Google Colab, and I know tpu runtimes can only access data in GCS as only the GCS file system is registered.
However I found StreamingFilesDataset can read tfrecord file from local.(https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tpu/datasets.py#L52 6)
I wrote like this
from tensorflow.python.tpu import datasets as tf_tpu_ds
tf_tpu_ds.StreamingFilesDataset( dataset_path, ‘tfrecord’, file_reader_job=‘localhost’)
Then I got

AttributeError: ‘OwnedIterator’ object has no attribute ‘string_handle’

‘string_handle’ seems tensorflow version 1 function.
So, Is StreamingFilesDataset version 1 only supported, or bugs?

Context: Hi Sabe, can you share a code snippet of the loading you are trying please?


How to MatMul two tensors inside custom c++ OP?

Question:
I’m trying to port Deformable Conv V2 to tensorflow and got a trouble: there is no any docs about how to estimate a usual matmul of 2 tensors inside c++.
Can someone help with example?
P.S.
There is a lot of computations for that matmul, so i expect that is should be something like a CPU/GPU functor template.

Context:
Take a look at:

      github.com/tensorflow/addons

      Add Modulated Deformable Convolution layer 2

      tensorflow:master ← Licht-T:add-deformable-conv

        opened

        Oct 8, 2020

          Licht-T

          +2874
          -0

    # Description

This is the implementation of [Modulated Deformable Convolution…](https://arxiv.org/abs/1811.11168). This fixes #179. There is another PR #1129, but that is stale and contaminated by [unknown license codes](https://github.com/tensorflow/addons/pull/1129#issuecomment-662063946). So I re-implemented this which is based on [the Torchvision's implementation](https://github.com/pytorch/vision/pull/1586).

~~I knew this would be too big to get reviewed, so, at first, I made the CPU only kernel with Eigen. When the CPU kernel is good enough, I will move to the next step: the GPU kernel implementation.~~
**UPDATE: GPU kernel available!**

## Type of change

- [ ] Bug fix
- [ ] New Tutorial
- [ ] Updated or additional documentation
- [ ] Additional Testing
- [ ] New Activation and the changes conform to the [activation contribution guidelines](https://github.com/tensorflow/addons/blob/master/tensorflow_addons/activations/README.md#contribution-guidelines)
- [ ] New Callback and the changes conform to the [callback contribution guidelines](https://github.com/tensorflow/addons/blob/master/tensorflow_addons/callbacks/README.md#contribution-guidelines)
- [ ] New Image addition and the changes conform to the [image op contribution guidelines](https://github.com/tensorflow/addons/blob/master/tensorflow_addons/image/README.md#contribution-guidelines)
- [x] New Layer and the changes conform to the [layer contribution guidelines](https://github.com/tensorflow/addons/blob/master/tensorflow_addons/layers/README.md#contribution-guidelines)
- [ ] New Loss and the changes conform to the [loss contribution guidelines](https://github.com/tensorflow/addons/blob/master/tensorflow_addons/losses/README.md#contribution-guidelines)
- [ ] New Metric and the changes conform to the [metric contribution guidelines](https://github.com/tensorflow/addons/blob/master/tensorflow_addons/metrics/README.md#contribution-guidelines)
- [ ] New Optimizer and the changes conform to the [optimizer contribution guidelines](https://github.com/tensorflow/addons/blob/master/tensorflow_addons/optimizers/README.md#contribution-guidelines)
- [ ] New RNN Cell and the changes conform to the [rnn contribution guidelines](https://github.com/tensorflow/addons/blob/master/tensorflow_addons/rnn/README.md#contribution-guidelines)
- [ ] New Seq2seq addition and the changes conform to the [seq2seq contribution guidelines](https://github.com/tensorflow/addons/blob/master/tensorflow_addons/seq2seq/README.md#contribution-guidelines)
- [ ] New Text addition and the changes conform to the [text op contribution guidelines](https://github.com/tensorflow/addons/blob/master/tensorflow_addons/text/README.md#contribution-guidelines)

# Checklist:

- [x] I've properly [formatted my code according to the guidelines](https://github.com/tensorflow/addons/blob/master/CONTRIBUTING.md#coding-style)
    - [ ] By running Black + Flake8
    - [x] By running pre-commit hooks
- [x] This PR addresses an already submitted issue for TensorFlow Addons
- [x] I have made corresponding changes to the documentation
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] This PR contains modifications to C++ custom-ops

# How Has This Been Tested?
`pytest` unit-testing

More in general If you are interested in custom ops:

    Deformable convolution and other custom ops MLIR

    Recently we had a refresh over a Deformable convloution WIP PR in Addons.
I’ve cherry-picked this as an example as this requires us to maintain almost 3k lines of new code in the repository.
This is maintainer-ship overhead is also quite similar to what we have with other custom kernels PRs.
As Addons is one of the few Ecosystem repositories to support custom (c++) ops and the related CI infra it is quite normal that we have this kind of proposed PRs.
But as the codeownership of these compon…


Custom loss function - “Shapes of all inputs must match”

Question:
Hi y’all… continuing the saga from my previous post. I’ve included code snippets for your viewing at the bottom. Let me know if you need more!
Currently, I’m trying to build out a GradientTape with just some integers I obtained from a custom loss function. It seems like it’s trying to find the gradient for multiple variables at once, as I had to change the GradientTape to persistent, or I got the following error:
RuntimeError: A non-persistent GradientTape can only be used to compute one set of gradients (or jacobians)
This workaround necessitates that I would manually delete the GradientTape later, which of course I’m not the biggest fan of…
Thanks for reading and take care!
=======================================================
Some output :
model_2: print loss_value_tensor in get grad f’n(48,)
model_2: print x shape in compute loss f’n(48, 28, 28, 1)
model_2: print y shape in compute loss f’n(48,)
model_2: print loss_value shape in compute loss f’n()
… And that will make sense when you see the code.
Error was: Shapes of all inputs must match: values[0].shape = [3,3,1,8] != values[1].shape = [8] [Op:Pack] name: initial_value
=======================================================
Here’s the code snippets I think you’d need to diagnose the problem. The matrices could be filled out with dummy data, since we’re just worried about the numpy array shapes, and the tensor shapes:

      gist.github.com

    https://gist.github.com/erick016/898ebb309ec9cfaae314aaef8ff0e385 3

  loss_fns
  #Training replacement

d = 0 #from algorithm 2, used in computing loss
#alpha = .33 #learning rate

#def nt_grad(curr_d):
    #return -1*alpha*(curr_d/BATCH_SIZE)

def compute_loss(model, x, y, training):
    out = model(x, training=training)
    This file has been truncated. show original

      gist.github.com

    https://gist.github.com/erick016/fbf91402b5b743a9d3f1467d081c165b 1

  bigL.py
      print("Reached Big L.")

    for batch_idx in range(NUM_BATCHES):
        #print("epoch_overall_loss_per_batch Index:" + str(epoch * NUM_BATCHES + batch_idx))
        print("batch_idx:" + str(batch_idx))
        #print("train_loss_per_batch_L1 Shape:" + str(np.shape(train_loss_per_batch_L1)))
        #print("train_loss_per_batch_L2 Shape:" + str(np.shape(train_loss_per_batch_L2)))
        #print("train_loss_per_batch_L3 Shape:" + str(np.shape(train_loss_per_batch_L3)))
        #print("epoch_overall_loss_per_batch Shape:" + str(np.shape(train_loss_per_batch_L3)))
        #print("===================================")
    This file has been truncated. show original

Context:
Relevant article I’m looking at:

      stackoverflow.com

  How to fix tensorflow "InvalidArgumentError: Shapes of all inputs must match" 14

  python, tensorflow, machine-learning, keras

  asked by

    Madison Sheridan

  on 10:41PM - 22 Jul 19 UTC

The actual custom optimizer I’m using:

      gist.github.com

    https://gist.github.com/erick016/30567f54946cf9e2804db2ab10da5dd4 1

  custom_optimizer.py
  #!/usr/bin/env python
# coding: utf-8

# In[1]:

#momentum "m_hat" and gradient "g_hat"

# In[2]:
    This file has been truncated. show original