# Tag: tensor

## Select pytorch tensor elements by list of indices

I guess I have a pretty simple problem. Let’s take the following tensor of length 6 Now I would like to to access only the elements at specific indices, lets say at [0, 3, 4]. So I would like to return I found torch.index_select which worked great for a tensor of two dimensions, e.g. dimension (2, 4), but not for

## Shuffling two 2D tensors in PyTorch and maintaining same order correlation

Is it possible to shuffle two 2D tensors in PyTorch by their rows, but maintain the same order for both? I know you can shuffle a 2D tensor by rows with the following code: To elaborate: If I had 2 tensors And ran them through some function/block of code to shuffle randomly but maintain correlation and produce something like the

## Behavior of Dataset.map in Tensorflow

I’m trying to take variable length tensors and split them up into tensors of length 4, discarding any extra elements (if the length is not divisible by four). I’ve therefore written the following function: This produces the output [<tf.Tensor: shape=(4,), dtype=int32, numpy=array([1, 2, 3, 4], dtype=int32)>], as expected. If I now run the same function using Dataset.map: I instead get

## Tensorflow: Issues with determining batch size in custom loss function during model fitting (batch size of “None”)

I’m trying to create a custom loss function, in which I have to slice the tensors multiple times. One example is listed below: This (and the entire loss function) works fine when testing it manually on selfmade Tensors y_true and y_pred, but when using it inside a loss function it will give an error upon model fitting (compiling goes fine).

## TensorFlow: How do I generate a dataset from two arrays?

I’ve been trying to generate a custom dataset from two arrays. One with the shape (128,128,6) (satellite data with 6 channels), and the other with the shape (128,128,1) (binary mask). I have been using the function tf.data.Dataset.from_tensor_slices: What I get is this: However, when I try to run this through my model I get this error: (None, 2) since my

## How to use tf.repeat() to replicate a specific column/row/slice?

this thread explains well the use of tf.repeat() as a tensorflow alternative to np.repeat(). one functionality which I was unable to figure out, in np.repeat(), a specific column/row/slice can be replicated by supplying the index. e.g. is there any tensorflow alternative to this functionality of np.repeat()? Answer You could use the repeats parameter of tf.repeat: where you get the first

## Using PyTorch tensors with scikit-learn

Can I use PyTorch tensors instead of NumPy arrays while working with scikit-learn? I tried some methods from scikit-learn like train_test_split and StandardScalar, and it seems to work just fine, but is there anything I should know when I’m using PyTorch tensors instead of NumPy arrays? According to this question on https://scikit-learn.org/stable/faq.html#how-can-i-load-my-own-datasets-into-a-format-usable-by-scikit-learn : numpy arrays or scipy sparse matrices. Other

## NumPy + PyTorch Tensor assignment

lets assume we have a tensor representing an image of the shape (910, 270, 1) which assigned a number (some index) to each pixel with width=910 and height=270. We also have a numpy array of size (N, 3) which maps a 3-tuple to an index. I now want to create a new numpy array of shape (920, 270, 3) which

## shape of an output tensor after convolutional filter on a colour image

I find it difficult to understand a notion about tensors. For VGG (https://www.tensorflow.org/api_docs/python/tf/keras/applications/VGG16), we start from a batch of colour images (none,224,224,3) and apply 64 2D convolutional filters. At the output we obtain a tensor of (none,224,224,64), we can see this by making a summary of the model. However, a filter must treat all 3 colours and my intuition tells

## Training MaskRCNN on custom data issue

I am trying to train Mask RCNN on a custom dataset of floorplans. I am following this article on Medium to do this: https://medium.com/analytics-vidhya/a-simple-guide-to-maskrcnn-custom-dataset-implementation-27f7eab381f2 . After having some issues with annotation formats and packages I got around to training the model. However, I stumbled upon the following error code: I could not find anything about this error and was hoping