36 questions
0
votes
1
answer
71
views
Batch items in Tensorflow Dataset that contain varying first dimension, but constant second dimension
I have a Tensorflow dataset that contains tensors of rank 2. Each tensor was read from a file and has varying first dimension and constant second dimension. For example, the shapes of each item can be ...
1
vote
0
answers
147
views
Pairs of ragged sequences as input for Tensorflow model
I have a model that takes pairs of sequences. The sequences are of variable length.
My model does this:
embeds each item of both sequences
sums embeddings of all items for each sequence
calculates ...
1
vote
0
answers
218
views
How to expand the dimensions of a ragged tensor in keras?
my goal: Using keras, I want to add a (non-ragged) dimension to a ragged tensor:
My initial ragged tensor has shape [batch size, (# time steps), # features].
I want a final ragged tensor with shape [...
0
votes
1
answer
224
views
How do I subtract a tensor from ragged tensor?
I am asking a question very similar to that of TensorFlow broadcasting of RaggedTensor
Basically, I am doing machine learning, and one data sample consists of a list of lists of coordinates, where ...
1
vote
0
answers
57
views
How to feed Images of different size being into the CNN
The problem being solved is a binary classification using CNN. Here I have images of different size. I am scaled down the images to 20% and normalizing them to the range (0,1) and obviously they still ...
1
vote
1
answer
632
views
Correct way to iterate over Keras ragged tensor
I have an input Tensorflow ragged tensor structured like this [batch num_images width height channels] and I need to iterate over the dimension num_images to extract some features relevant for ...
2
votes
1
answer
363
views
Tensorflow dataset with variable number of elements
I need a dataset structured to handle a variable number of input images (a set of images) to regress against an integer target variable.
The code I am using to source the images is like this:
import ...
1
vote
1
answer
299
views
strip and filter strings in ragged tensor
I would like learn if there is a decent and tensorflownic way to do follow conversion. Basically each string(row) as several words, and each word has a suffix like "%1", and goal is to strip ...
0
votes
1
answer
274
views
Pandas rows containing numpy ndarrays various shapes
I'd creating a Pandas DataFrame in which each particular (index, column) location can be a numpy ndarray of arbitrary shape, or even a simple number.
This works:
import numpy as np, pandas as pd
x = ...
0
votes
1
answer
321
views
Tensorflow concat ragged tensor returning wrong shape
I need to concat two ragged tensors keeping the last dimension with a fixed size 2.
Checking model.output_shape I get the desired (None, None, 2). But when I call the model, I get (batch_size, None, ...
2
votes
0
answers
351
views
How to provide two inputs to a Tensorflow Model using ragged tensors?
I am trying to create a model with two inputs. The model is very simple containing only one lstm layer for each input. The problem is that I want to provide lists of different length as inputs. For ...
1
vote
0
answers
478
views
Dense layer only supports RaggedTensors when the innermost dimension is non-ragged. Received: inputs.shape=(None, None, None)
I have a tf.data.dataset with 2 and 3 dimensional ragged tensors:
[
[1,2,3,4],
[5,6,7,8],
...
]
and [
[[1,2,3],
[4,5,6]
],
[[7,8,9],
[10,11,12],
...
]
]
...
2
votes
0
answers
417
views
'RaggedTensor' object has no attribute 'set_shape' when passing RaggedTensor to BatchNormalization layer in Tensorflow 2.8
I am trying to pass a 3D RaggedTensor of shape (batch_size=None, 1, 136) to a batch normalization layer, but am receiving the error in the title. I assume because RaggedTensors can very in dimensions, ...
1
vote
1
answer
804
views
how to pad sequences in a tensor slice dataset in TensorFlow?
I have a tensor slice dataset made from two ragged tensors.
tensor_a is like: <tf.RaggedTensor [[3, 3, 5], [3, 3, 14, 4, 17, 20], [3, 14, 22, 17]]>
tensor_b is like: <tf.RaggedTensor [[-1, 1, ...
0
votes
1
answer
837
views
How to save ragged tensor as a file?
How can I save a ragged tensor as a file on my disk and then reuse it in calculations opening it from the disk? Tensor consists of a nested array of numbers with 4 signs after the point. (I'm working ...
1
vote
1
answer
589
views
Sample from ragged tensor
I have a raggedTensor of row_lens going from 1 to up to 10k. I would like to select elements randomly from it with an upper limit on the number per row in a scalable way. Like in this example:
vect = [...
1
vote
1
answer
4k
views
IndexError: Dimension out of range (expected to be in range of [-2, 1], but got 3)
I created a random function with the line below
x = torch.randn(4, 3)
and used the transpose function as shown here
torch.transpose(x, 0, 1)
I got the error line below. Who can assist with a ...
1
vote
1
answer
810
views
Error when trying to stack two ragged tensors
I'm getting an odd error when trying to use tf.ragged.stack. I'm trying to stack two tensors t1, t2, however they have different rank. t2 is 1 rank less than t1. Therefore I used tf.expand_dims to ...
0
votes
2
answers
705
views
How to slice according to batch in the tensorflow array?
I have an array output and a id subject_ids.
output = [[[1, 2, 3]], [[4, 5, 6]], [[7, 8, 9]]]
subject_ids = [[0, 1], [1, 2], [0, 2]]
The numbers in ID represent the start and end positions ...
1
vote
1
answer
485
views
Apply linear algebra to ragged tensor in tensorflow
I'm using tensorflow v2.7.0 and trying to create a ML model using ragged tensor.
The issue is that tf.linalg.diag, tf.matmul and tf.linalg.det are not working with ragged tensor.
I've found a ...
1
vote
1
answer
665
views
Error with tensorflow map_fn. Unable to specify output signature
I am trying to use tensorflow's tf.map_fn to map a ragged tensor but I am getting an error that I can't fix.
Here is some minimal code that demonstrates the error:
import tensorflow as tf
X = tf....
1
vote
0
answers
201
views
How to use ragged-tensor to implement the following loop code in tensorflow2?
g=tf.random.normal([1000,627,16,1])
ind1=tf.constant(np.random.randint(100,size=(251,128,128,3)))
ind2=tf.constant(np.random.randint(100,size=(150,128,128,3)))
ind3=tf.constant(np.random.randint(100,...
0
votes
0
answers
152
views
How to fit smaller spheres inside a 3D shape such as Mickey Mouse?
I am looking at a problem that takes in an argument of a 3D STL file -> Shape and (rmin -> Minimum Radius) and fits in a maximum number of spheres inside the shape. The function should spit out ...
2
votes
1
answer
821
views
Tensorflow tf.map_fn over ragged tensor fails with object of type 'RaggedTensor' has no len
This Tensorflow doc gives this example of using tf.map_fn on ragged tensors which works for Tensorflow 2.4.1 and above:
digits = tf.ragged.constant([[3, 1, 4, 1], [], [5, 9, 2], [6], []])
print(tf....
3
votes
1
answer
2k
views
Ragged Tensors have no len() after conversion to Tensor
I am training a deep learning model on stacks of images with variable dimensions. (Shape = [Batch, None, 256, 256, 1]), where None can be variable.
I use tf.RaggedTensor.merge_dimsions(0,1) to ...
0
votes
0
answers
190
views
How to transform a list of 2D-arrays (with one dimension varies) to a ragged tensor?
x is a list of 2D-arrays, and each 2D-array is a series of 6-tuple.
I want to transform x into a ragged tensor. I try
xrag = tf.ragged.constant(x) and
get xrag with shape = (895, None, None), ...
1
vote
0
answers
272
views
Problem with TensorFlow(2.4.0) Model Training with RaggedTensor input
I am trying to train a TF model that will look at a customer's cart values regarding food categories and predict what food category the customer will be interested in next.
There are only 5 types of ...
0
votes
0
answers
116
views
Tensorflow: Reshape a 1-D tensor with given numbers of elements in each row
I want to convert a 1-D tensor to 2-D shape in Tensorflow 2, with the number of elements in each row is given. I found a solution using the RaggedTensor like this
numbers = tf.constant([1,3,2,5,4])
c0 ...
1
vote
0
answers
260
views
Ragged tensor slicing with tf.newaxis does not work. tf.expand_dims does though
I have a ragged tensor seq (num_sentences, num_words, word_dim). If I want to add a new axis (dimension) at the end with a slice seq[..., tf.newaxis], it fails with the error below.
tf.expand_dims(seq,...
3
votes
0
answers
606
views
RaggedTensor on TPU
I am trying to train a neural network using TensorFlow that takes as input (tf.keras.layers.Input) a RaggedTensor. It works fine on CPU and GPU but I am really strugling to make it work on TPU. I ...
1
vote
1
answer
1k
views
Reshape Tensorflow RaggedTensor
I have a 4D RaggedTensor of shape (batch_size, None, None, 100), I want to create from this a tensor of shape (batch_size, None, 100). So basically merging 1st and 2nd dimensions, but not including ...
1
vote
1
answer
1k
views
Tensorflow: How to use a Ragged Tensor as an index into a normal tensor?
I have a 2D RaggedTensor consisting of indices I want from each row of a full tensor, e.g.:
[
[0,4],
[1,2,3],
[5]
]
into
[
[200, 305, 400, 20, 20, 105],
[200, 315, 401, 20, 20, ...
0
votes
2
answers
1k
views
(tensorflow 2.4.1)how to get a ragged tensor has determinate last dimension shape?
like this:
'''
a = [1.0, 2.0, 3.0]
b = [[a, a, a, a], [a, a, a], [a, a, a, a, a, a, a], [a, a]]
c = tf.ragged.constant(b, dtype=tf.float32)
'''
I got a tensor with shape : [4, None, None], but i ...
0
votes
1
answer
815
views
Tensorflow create tf.ragged.constant from a large dataset
Having a DF of 50,000 users each having different count of rows:
id feature_1 ... feature10 feature11
0 1587712104294-4384584 -0.661835 ... ...
8
votes
2
answers
2k
views
Broadcast and concatenate ragged tensors
I have a ragged tensor of dimensions [BATCH_SIZE, TIME_STEPS, EMBEDDING_DIM]. I want to augment the last axis with data from another tensor of shape [BATCH_SIZE, AUG_DIM]. Each time step of a given ...
3
votes
2
answers
4k
views
RaggedTensor request to TensorFlow serving fails
I've created a TensorFlow model that uses RaggedTensors. Model works fine and when calling model.predict and I get the expected results.
input = tf.ragged.constant([[[-0.9984272718429565, -0....