c3di / im2im

im2im: Automatically Converting In-Memory Image Representations using A Knowledge Graph Approach
MIT License
1 stars 0 forks source link

Conversion tasks #49

Closed Max-ChenFei closed 6 months ago

Max-ChenFei commented 6 months ago

Task1: torch tensor on GPU -> tensorflow tensor on GPU 

  1. Move the PyTorch tensor from GPU to CPU: If your PyTorch tensor is on the GPU, you first need to move it to the CPU using the .cpu() method.
  2. Convert the PyTorch tensor to a NumPy array: Once the tensor is on the CPU, you can convert it to a NumPy array using the .numpy() method. Note that this step can only be done on a CPU tensor.
  3. channel last to channel first
  4. Create a TensorFlow tensor from the NumPy array: Use TensorFlow's functions to convert the NumPy array into a TensorFlow tensor.
  5. Move the TensorFlow tensor to GPU: Finally, use TensorFlow's .gpu() method to move the tensor to the GPU.

more related visualization

Max-ChenFei commented 6 months ago

Taks 2 PIL to torch image 4 step

img = np.array(pic, copy=True)
img = torch.as_tensor(img)
img = img.view(pic.size[1], pic.size[0], F_pil.get_image_num_channels(pic))
# put it from HWC to CHW format
img = img.permute((2, 0, 1))
Max-ChenFei commented 6 months ago

Tasks3

from tensorflow gpu float 0-1 -> torch float32 full range gpu