TensorFlow Wide and Deep Model , how many features can I use ? - tensorflow

In this wide and deep model with tensorflow https://www.tensorflow.org/tutorials/wide_and_deep, is there a limit of number of features? I mean is it possible to use 20 columns for training and prediction ?
I tried to train my model with 20 columns, and to predict, but I had this error below
Exception during running the graph: Unable to get element as bytes.
I didn't really understand this error, but I think it is linked to the number of features, cause when I tried with 19 columns, prediction worked!
PS: I'm working on GCP with GCS and GCMLE
Here is the model on my github https://github.com/SofiaAmel/censusTest/blob/master/trainer/model.py

There are no limits to the number of columns. The error you are seeing probably indicates some problem specifically with the column you added.

Related

TensorFlow Servering returns incorrect results

I have 2 different models (Model A is Keras .h5 and Model B is Torch .pth). They need to be served with TFServing. I converted both of these models to Tensorflow (with index .pb) for serving.
I succeeded to serve and get the outputs, but when I compared serving results with the straight model's outputs (on Keras and Torch model), I found that it had made wrong results. The prediction's score for the same image on the server-side is more unreliable than in model output. I could not understand, whether it raises from faults in model converting or anything else?
How could I fix it?
The reason of different results is due to different default parameters of layers and optimizer. For example in pytorch decay-rate of batch-norm is considered as 0.9, whereas in keras it is 0.99. Like that, there may be other variation in default parameters.
I would also recommend to check the weight initializations, as they might be different between both frameworks. Thank you!

how to manage batches for model.provide_groundtruth

I'm trying to use TensorFlow 2 Object Detection API with a custom dataset for multi classes to train an SSD, I took as base the example provide by the documentation: https://github.com/tensorflow/models/blob/master/research/object_detection/colab_tutorials/eager_few_shot_od_training_tf2_colab.ipynb
My current problem is when I start the fine tuning:
InvalidArgumentError: The first dimension of paddings must be the rank
of inputs[2,2] [6] [Op:Pad]
That seems to be related with the section of model.provide_groundtruth on train_step_fn, as I mention I took my data from a TensorFlow record, I mapped this to a dataset and divide it into batches using padded_batches(tf.data.TFRecordDataset) seems that this is the correct to feed the training with the image but now my problem is the groundtruth because this now is also converted to batches [batch_size,num_detections,coordinate_bbox], is this the problem? any idea on how to fix this issue.
Thanks
P.S. I tried to used the version of modified the pipeline.config file and run the model_main_tf2.py as was in the past with TensorFlow 1 but this method is buggy.
Just to share with everyone this resolves my issue was that I manage to split the data into batches the images and ground truth correctly but I never convert my labels to one hot vector encoding.

What is Keras doing if my sample size is smaller than my batch size?

fairly new to LSTM, but I already searched for a solution and could not find anything satisfying or even similar enough.
So here is my problem:
I am dealing with sleep classifaction and have annotated records for about 6k patients.
To train my bidirectional LSTM, I pick one patient and fit the model on that data instead of putting all the data from all the patients into one big matrix because I want to prevent patient samples mixing when Keras is training with mini batches.
The sequence length or samples_size per patient are not the same.
Then I loop over all patients and do a additional loop for the number of epochs I considered to train the model for (as described in Developer Guides).
So since LSTMs (if not stateful) reset their cell and hidden state after each batch and the default batch_size for tf.keras.Sequential.fit() is 32 I wanted it to match the sample_size of the patient I am showing to the network. If I do so I am getting a warning and the training process errors after some time. The error is:
WARNING:tensorflow:6 out of the last 11 calls to .distributed_function at 0x0000023F9D517708> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings is likely due to passing python objects instead of tensors. Also, tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. Please refer to https://www.tensorflow.org/beta/tutorials/eager/tf_function#python_or_tensor_args and https://www.tensorflow.org/api_docs/python/tf/function for more details.
So I looked up what my longest sample_size is and set my batch_size accordingly.
tl;dr: What is Keras doing in all the instances where my variable sample_size is not matching my batch_size=max(len(sample_size))?
Is it just showing the available samples to the network?
If so: Why is there the warning mentioned above where setting the batch_size=sample_size leads to the failed training?
Or is it showing the available samples to the network and filling up the rest with zeros to match the given batch_size?
If so: Why is there the necessity of masking when using e.g. stateful mode?
edit:
So, I tried some additional workarounds and built my own Data Generator, which proves data of one patient as one batch. I then set steps_per_epoch=len(train_patients) to include all patients into one epoch. No warnings about retracing, which I do not understand either.
It seems to solve my problem of showing one patient per batch without mixing patient data and have a variable sample_size, but I really do not understand the differences between all these posibilities and their different warnings.

Error incompatible shapes in function model.fit()

I am new in Keras. I want to try U-net. I used this tutorial from tensorflow: https://github.com/tensorflow/models/blob/master/samples/outreach/blogs/segmentation_blogpost/image_segmentation.ipynb.
I used the code for U-net creation with my own dataset. They have got images 256x256x3 and I made my images with same shape.
Now, I got error:
InvalidArgumentError: Incompatible shapes: [1376256] vs. [458752]
[[{{node training/Adam/gradients/loss/conv2d_23_loss/mul_grad/BroadcastGradientArgs}}] ]
It is in function model.fit(). I have got 130 training examples and batch size is 5 (I know, that those number are small...).
Please, Can anybody know, what can cause this error in function model.fit()?
Thank you for your help.
1376256 is exactly 3 x 458752. I suspect you are not correctly accounting for your channels somewhere. As this appears to be on your output layer, it may be that you're trying to predict 3 classes when there are only 1.
In future, or if this doesn't help, please provide more information including the code for your model and number of classes you're trying to predict, so people can better help.

Expected accuracy of the pet example using SSD model in TensorFlow object detection API?

I'm using default pipeline configuration (ssd_inception_v2_pets.config) and pretrained inception v2 COCO model. In TensorBoard, the loss continues decreasing, but the average precision isn't getting any better. Has anyone done similar experiment using inception v2 for SSD? What's your experience?
The reason of the low mAP is due to extreme low score threshold at non maximum suppression step. The result of such low threshold is that almost every image would produces more than 70 detections, while there's only one ground truth in each image. Changing this threshold to a more reasonable value -- 0.1 -- produces much better mAP plot.
You may have been bitten by this issue: https://github.com/tensorflow/models/issues/2749
as I was.
Try updating & grabbing one of the new starting pretrained files, and seeing if your problem is resolved.