hon 3.12 scribt that upscales all images with waifu2x. Use spandrel to implement…
- User
hon 3.12 scribt that upscales all images with waifu2x. Use spandrel to implement waifu2x. The programm should go through D:\Bilder\Python\1. Input and its subfolders and save all processed images in D:\Bilder\Python\2. Output keeping the same folder structure. Use pillow and numpy. Model Location: D:\Bilder\Python\0. Code\Requirements\Models\Scale2x_Noise0.pth Information about spandrel: Project description Spandrel
PyPI package version number PyPi Downloads Python Version Documentation
Actions Status License Contributors
Spandrel is a library for loading and running pre-trained PyTorch models. It automatically detects the model architecture and hyperparameters from model files, and provides a unified interface for running models.
After seeing many projects extract out chaiNNer's model support into their own projects, I decided to create this PyPi package for the architecture support and model loading functionality. I'm also hoping that by having a central package anyone can use, the community will be encouraged to help add support for more models.
This package does not yet have easy inference code, but porting that code is planned as well. Installation
Spandrel is available through pip:
pip install spandrel
Basic Usage
While Spandrel supports different kinds of models, this is how you would run a super resolution model (e.g. ESRGAN, SwinIR, HAT, etc.):
from spandrel import ImageModelDescriptor, ModelLoader import torch load a model from disk
model = ModelLoader().load_from_file(r"path/to/model.pth") make sure it's an image to image model
assert isinstance(model, ImageModelDescriptor) send it to the GPU and put it in inference mode
model.cuda().eval() use the model
def process(image: torch.Tensor) -> torch.Tensor: with torch.no_grad(): return model(image)
Note that model is a ModelDescriptor object, which is a wrapper around the actual PyTorch model. This wrapper provides a unified interface for running models, and also contains metadata about the model. See ImageModelDescriptor for more details about the metadata contained and how to call the model.
NOTE: ImageModelDescriptor will NOT convert an image to a tensor for you. It is purely making the forward passes of these models more convenient to use, since the actual forward passes are not always as simple as image in/image out.
More architectures
If you are working on a non-commercial open-source project or a private project, you should use spandrel and spandrel_extra_arches to get everything spandrel has to offer. The spandrel package only contains architectures with permissive and public domain licenses (MIT, Apache 2.0, public domain), so it is fit for every use case. Architectures with restrictive licenses (e.g. non-commercial) are implemented in the spandrel_extra_arches package.
- Assistant