Home

Awesome

tf-slice-assign

GitHub Workflow Build Status

A tool for assignment to a slice in TensorFlow.

In TensorFlow, as opposed to Pytorch, it is currently impossible to assign to the slice of a tensor in a range of different settings. To mitigate this issue, tf-slice-assign introduces a single function that allows to do exactly this using tensor_scatter_nd_update.

Use

from tf_slice_assign import slice_assign

new_tensor = slice_assign(old_tensor, assignment, *slice_args)

You can find a relatively simple example here.

Installation

pip install tf-slice-assign

List of GitHub issues and StackOverflow questions regarding TensorFlow slice assignment

In the following table, I am trying to give the reasons as to why no mitigation for the current problem exists.

LinkStatus
SOCurrent answer requires creating a tf.Variable for each slice assignment you make
GHQuestion is about tf.Variable
SOAnswers for tf.Variable or using tensor_scatter_update in a non-adaptable way
GHSuggestion to use tensor_scatter_nd_update
GHAn answer suggest creating a mask, but a mask can actually be as difficult to create as the indices for tensor_scatter_nd_update