A collection of small functions that supplements torch functionality
Project description
TorchFun (originally Torchure)
for those who expect more convenient features from torch
Functionality
- flatten(tensor)
- imshow(tensor_batch)
- load
Install TorchFun
pip install torchfun
API
Flatten (Module)
used to reshape outputs
Usage:
flat = Flatten()
out = flat(x)
flatten (function)
Usage:
out = flatten(x)
imshow (function)
only deal with torch channel-first image batch,
Arguements:
- x: input data cube, torch tensor or numpy array.
- title: add title to plot. (Default None)
- title can be string, or any string-able object.
- auto_close: (default True)
- Close the pyplot session afterwards.
- Clean the environment just like you had never used matplotlib here.
- if set to False, the plot will remain in the memory for further drawings.
Usage:
imshow(batch)
imshow(batch,title=[a,b,c])
imshow(batch,title='title')
imshow(batch,auto_close=False)
Warnings:
TorchFun:imshow:Warning, you are using WebAgg backend for Matplotlib.
Please consider windowed display SDKs such as TkAgg backend and GTK* backends.
This means your matplotlib is using web-browser for figure display. We strongly recommend you to use window-based native display because browser-based backends are fragile and tend to crash. You can change the display mamanger for matplotlib each time you execute your script by:
import matplotlib
matplotlib.use('TkAgg') # or GTK GTKAgg
or permanantly by editing: site-packages/matplotlib/mpl-data/matplotlibrc
and change backend to TkAgg
A full list of available backends can be found at:
import matplotlib
matplotlib.rcsetup.all_backends
and, the TCL/TK GUI library for tkinter
can be downloaded here.
load(a,b) (function)
Arguements:
- arbitrary arguemnts named :
a
andb
Load weighta
into modelb
, or load modelb
using weighta
The order of the arguments doesn't matter. Example:
>load('weights.pts',model)
or
>load(model,'weights.pts')
or
>f = open('weight.pts')
>load(f,model)
or
>load(model,f)
Return value:
- None
save(a,b) (function)
Arguements:
- arbitrary arguemnts named :
a
andb
save weighta
into targetb
, or save modelb
into targeta
The order of the arguments doesn't matter.
Example:
>save('weights.pts',model)
or
>save(model,'weights.pts')
or
>f = open('weight.pts')
>save(f,model)
or
>save(model,f)
or
>save('weights.pts',state_dict)
or
>save(state_dict,'weights.pts')
Return value: None
count_parameters(model_or_dict) (function)
Arguements: * model_or_dict: model or state dictionary Return: parameter amount in python-int Returns 0 if datatype not understood Usage:
count_parameters(model)
count_parameters(state_dict)
count_parameters(weight_tensor)
count_parameters(numpy_array)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for torchfun-0.0.20-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 350deb02120af2bbfac3317bbaf12f4cd7d10ac06b219d497e775a5193437845 |
|
MD5 | 22ff748fcc95237f8e0f101509cdd862 |
|
BLAKE2b-256 | 24af4ff720b4a6a0087a4efbf91b6f1600dd0877ee3d40641e4d034feb1955bb |