CivArchive
    ← All articles
    Published September 9, 2024by zentrocdot

    Simple Print of PT File Structure

    62 views0 reactions0 comments on CivitAI0 collected
    tool guidehypernetworkembeddingpython utilitypython

    Foreword

    While trying to understand the PickleTensor files I have to deal with I came up with this small Python script. The script uses Python for simply printing the dir and file structure of a given .pt file.

    The question came up, when I renamed a .pt file to another name or better name and took a look into the file itself. It was not clear if this is permitted without changing the behaviour of the Embedding or Hypernetwork itself.

    Simple Script

    The subsequently listed Python3 script is printing the dir and file structure of a .pt file.

    #!/usr/bin/python
    #
    # Version 0.0.0.1
    
    # Import module.
    import zipfile
    
    # Set filename.
    PT_FILE = "embedding_file_name.pt"
    
    # Open file for reading.
    with zipfile.ZipFile(PT_FILE, mode="r") as archive:
        # Print file structure.
        archive.printdir()

    This file and others can be found in my GitHub account [1].

    Final Remark

    As far as I see up to now, it is possible to rename a .pt file without problems. This statement is not valid if modifications are done inside the file structure like renaming dirs or files and changing content in some files if sensible or not.

    This way the .pt filetype itself is somehow secure. Somehow is relative in this sense. A modification inside the given file structure will be recognized by the system. Then the systems says it is malicious code.

    Finally

    Have a nice day! Have fun! Be inspired!

    Reference

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