santa hat
deerdeer nosedeer glow
Sign In

Simple PickleTensor File Analysis

Simple PickleTensor File Analysis

Foreword

While preparing PickleTensor .pt files (Embedding and Hypernetwork) for use here at CIVITAI, the question came up, if it is possible to get some basic data from a .pt file a short while after training or later on. This article is my first personal answer after some minutes of research.

Retrieve Basic Informations from a .pt File

Following simple Python3 script can be used to retrieve some basic data from a .pt file and print them out.

#!/usr/bin/python3
''' Read data from .pt file and print the data.'''

# Import standard Python module warnings.
import warnings

# Ignore (torch) future warning.
warnings.simplefilter(action='ignore', category=FutureWarning)

# Import third party module torch.
import torch

# Set the file name.
PT_FILE = "name_of_embedding.pt"

# Get data.
data = torch.load(PT_FILE)

# Print data.
print(data)

# Exit script.
exit()

Explanation

First, FutureWarning from module torch will be catched. Second, the required Python module torch is loaded, which produces some warnings while script is running. Then the file of interest is loaded by the load method of module torch. After that, the retrieved data is printed out.

Final Words

On GitHub [1] the scripts can be found, I am preparing in parallel to my work here at CIVITAI.

Resources

[1] https://github.com/zentrocdot/artificial-intelligence-tools/tree/main/python

[2] https://pytorch.org/docs/stable/generated/torch.load.html

[3] https://pypi.org/project/torch/

Finally

Have a nice day! Have fun! Be inspired!

0

Comments