tomosipo.links.torch module
This module adds support for torch arrays as astra.data3d backends
This module is not automatically imported by tomosipo, you must import it manually as follows:
>>> import tomosipo as ts
>>> import tomosipo.torch_support
Now, you may use torch tensors as you would numpy arrays:
>>> vg = ts.volume(shape=(10, 10, 10))
>>> pg = ts.parallel(angles=10, shape=10)
>>> A = ts.operator(vg, pg)
>>> x = torch.zeros(A.domain_shape)
>>> A(x).shape == A.range_shape
True
You can also directly apply the tomographic operator to data on the GPU:
>>> A(x.cuda()).is_cuda
True
- class tomosipo.links.torch.TorchLink(shape, initial_value)[source]
Bases:
LinkLink implementation for torch arrays
- clone()[source]
- context()[source]
Context-manager to manage ASTRA interactions
This context-manager makes sure that the current CUDA stream is set to the CUDA device of the current linked data.
- Returns:
- Return type:
- property data
Returns a shared array with the underlying data.
Changes to the return value will be reflected in the astra data.
If you want to avoid this, consider copying the data immediately, using x.data.clone() for instance.
NOTE: if the underlying object is an Astra projection data type, the order of the axes will be in (Y, num_angles, X) order.
- Returns:
torch.Tensor
- Return type:
torch.Tensor
- property linked_data
Returns a numpy array or GPULink object
- Returns:
- Return type:
- new_empty(shape)[source]
- new_full(shape, value)[source]
- new_zeros(shape)[source]