Saravanan666/pypi-org huggingface dataset:
Package: torchlop
PyTorch-layerwise-OpCounterA tool for profile the MACs, parameters, input_shape, output_shape et.al of each layer in Pytorch model.
Forked from Lyken17/pytorch-OpCounter which is not supporting layer-wise profile and I will follow it.How to installpip install torchlopORpip install --upgrade git+https://github.com/hahnyuan/pytorch-layerwise-OpCounter.gitHow to useBasic usagefromtorchvision.modelsimportresnet50fromtorchlopimportprofilemodel=resnet50()input=torch.randn(1,3,224,224)macs,params,layer_infos=profile(model,inputs=(input,))The layer_infos is a dict that contains the infos for each layer of the pytorch model.The key is the name of the layer'type': the class name of the layer'in_size': input size'out_size': output size'ops': operations (MACs)'params': parametersDefine the rule for 3rd party module.classYourModule(nn.Module):# your definitiondefcount_your_model(model,x,y):# your rule hereinput=torch.randn(1,3,224,224)macs,params,layer_infos=profile(model,inputs=(input,),custom_ops={YourModule:count_your_model})Write the layerwise profile information into a csv filefromtorchvision.modelsimportresnet50fromtorchlopimportprofilefromtorchlop.rst_processimportwrite_csvmodel=resnet50()input=torch.randn(1,3,224,224)macs,params,layer_infos=profile(model,inputs=(input,))csv_file='profile.csv'write_csv(csv_file,layer_infos)Results of Recent ModelsThe implementation are adapted fromtorchvision. Following results can be obtained usingbenchmark/evaluate_famours_models.py.ModelParams(M)MACs(G)alexnet61.100.77vgg11132.867.74vgg11_bn132.877.77vgg13133.0511.44vgg13_bn133.0511.49vgg16138.3615.61vgg16_bn138.3715.66vgg19143.6719.77vgg19_bn143.6819.83resnet1811.691.82resnet3421.803.68resnet5025.564.14resnet10144.557.87resnet15260.1911.61wide_resnet101_2126.8922.84wide_resnet50_268.8811.46ModelParams(M)MACs(G)resnext50_32x4d25.034.29resnext101_32x8d88.7916.54densenet1217.982.90densenet16128.687.85densenet16914.153.44densenet20120.014.39squeezenet1_01.250.82squeezenet1_11.240.35mnasnet0_52.220.14mnasnet0_753.170.24mnasnet1_04.380.34mnasnet1_36.280.53mobilenet_v23.500.33shufflenet_v2_x0_51.370.05shufflenet_v2_x1_02.280.15shufflenet_v2_x1_53.500.31shufflenet_v2_x2_07.390.60inception_v327.165.75
Package: torch-lr-scheduler
torch-lr-schedulerPyTorch Optimizer Lr Scheduler.InstallationNeed Python 3.6+.pipinstalltorch-lr-schedulerUsageimporttorch_lr_schedulerlr_scheduler=torch_lr_scheduler.factory(config={'line_chain':[{# warm up to 0.8'mode':'linear','ratio':0.01,'start':0.2,'target':0.8},{# cosine to 0.0'mode':'cosine','ratio':1.0,'target':0.0}]})print(lr_scheduler)#> LrScheduler (learning_rate_scale: 1.0) with LineChain (#>     1.0%, linear from 0.2 to 0.8,#>   100.0%, cosine from 0.8 to 0.0,#> )
Package: torch-lucent
LucentPyTorch + Lucid = LucentThe wonderfulLucidlibrary adapted for the wonderful PyTorch!Lucent is not affiliated with Lucid or OpenAI's Clarity team, although we would love to be!Credit is due to the original Lucid authors, we merely adapted the code for PyTorch and we take the blame for all issues and bugs found here.UsageLucent is still in pre-alpha phase and can be installed locally with the following command:pip install torch-lucentIn the spirit of Lucid, get up and running with Lucent immediately, thanks to Google'sColab!You can also clone this repository and run the notebooks locally withJupyter.Quickstartimport torch

from lucent.optvis import render
from lucent.modelzoo import inceptionv1

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model = inceptionv1(pretrained=True)
model.to(device).eval()

render.render_vis(model, "mixed4a:476")TutorialsOther NotebooksHere, we have tried to recreate some of the Lucid notebooks! You can also check out thelucent-notebooksrepo to clone all the notebooks.Recommended ReadingsFeature VisualizationThe Building Blocks of InterpretabilityUsing Artiﬁcial Intelligence to Augment Human IntelligenceVisualizing Representations: Deep Learning and Human BeingsDifferentiable Image ParameterizationsActivation AtlasRelated TalksLessons from a year of Distill ML Research(Shan Carter, OpenVisConf)Machine Learning for Visualization(Ian Johnson, OpenVisConf)SlackCheck out#proj-lucidand#circuitson theDistill slack!Additional InformationLicense and DisclaimerYou may use this software under the Apache 2.0 License. SeeLICENSE.
Package: torchlurk
IntroductionCNNs do a great job at recognizing images (when appropriately trained).Problems arise when it comes to interpret the network: although one coded the network in question and knows all the tips and tricks necessary to train it efficiently, one might ignorehowit generates the output from a given image.Torchlurk aims at helping the user in that sense: it provides an interface to visualize a Pytorch network in an efficient yet simple manner, similarly toMicroscope.All you need is the trained Pytorch network and its training set. That's it.Installation ☕Torchlurk is available on pip! Just run:pip install torchlurkOverview ☝Documentation 📚Torchlurk has anonline documentationwhich gets regularly updated.Quick Start ⌛Your training set should follow the following structure in order for the lurker to load properly your datas:.
├── src                  
│   ├── name_class1
│   │   ├── class1id_1.jpg
│   │   ├── class1id_2.jpg
│   │   ├── ...
│   ├── name_class2
│   │   ├── class2id_1.jpg
│   │   ├── class2id_2.jpg
│   │   ├── ...
│   ├── ...1. Instanciationimporttorchlurkimporttorch# load the trained modelyour_model=ModelClass()your_model.load_state_dict(torch.load(PATH))# the preprocess used for the trainingpreprocess=transforms.Compose(...)# and instanciate a lurkerlurker=Lurk(your_model,preprocess,save_gen_imgs_dir='save/dir',save_json_path='save/dir',imgs_src_dir=".source/dir",side_size=224)2. Layer VisualizationThe layer visualization is an artificial image generated by gradient descent which aims at maximizing the acivation of a given filter: this gives useful insights on the type of texture/colors the filter in question is looking at in inputs images.# compute the layer visualisation for a given set of layers/filterslurker.compute_layer_viz(layer_indx=12,filter_indexes=[7])# OR compute it for the whole networklurker.compute_viz()# plot the filterslurker.plot_filter_viz(layer_indx=12,filt_indx=7)3. Max ActivationThe max activation represents the top N images activating a given filter the most in terms of average or max score.#compute the top activation imageslurker.compute_top_imgs(compute_max=True,compute_avg=True)# plot themlurker.plot_top("avg",layer_indx=12,filt_indx=7)3.1 Deconvolution# plot the max activating images along with their cropped areaslurker.plot_crop(layer_indx=2,filt_indx=15)4. GradientsGuided GRAD CAM is another way to check what a given filter is looking at: it relies in particular in isolating a specific location in the image that excites our neurons. For more information, checkthis article.#compute the gradientslurker.compute_grads()# plot themlurker.plot_top("avg",layer_indx=12,filt_indx=7,plot_imgs=False,plot_grads=True)5. HistogramsTorchlurk allows you to visualize the most activating classes of the training using histograms: a very peaked distribution is often asssociated with a specialized filter.# display thelurker.plot_hist(layer_indx=12,filt_indx=7,hist_type="max",num_classes=12)6. ServingTorchlurk is equiped with a live update tool which allows you to visualize your computed results while coding.#serve the application on port 5001lurker.serve(port=5001)lurker.end_serve()Happy Lurking!🕵
Package: torchmanager-diffusion
Torchmanager Diffusion Models Plug-inThe torchmanager implementation for diffusion models.Pre-requisitesPython >= 3.9SciPy>= 1.11.4PyTorch>= 2.0.1LPIPStorchmanager>= 1.2einops>= 0.6.1InstallationPyPi:pip install --pre torchmanager-diffusionDDPM Manager UsageTrain DDPMDirect compileDDPMManagerwith a model, a beta space, and a number of time steps. Then, usefitmethod to train the model.importdiffusionfromdiffusionimportDDPMManagerfromtorchmanagerimportcallbacks,data,losses# initialize datasetdataset:data.Dataset=...# initialize model, beta_space, and time_stepsmodel:torch.nn.Module=...beta_space:diffusion.scheduling.BetaSpace=...time_steps:int=...# initialize optimizer and loss functionoptimizer:torch.optim.Optimizer=...loss_fn:losses.Loss=...# compile the ddpm managermanager=DDPMManager(model,beta_space,time_steps,optimizer=optimizer,loss_fn=loss_fn)# initialize callbackscallback_list:list[callbacks.Callback]=...# train the modeltrained_model=manager.fit(dataset,epochs=...,callbacks=callback_list)Evaluate DDPMAdd necessary metrics and usetestmethod withsampling_imagesasTrueto evaluate the trained model.importtorchfromdiffusionimportDDPMManagerfromtorchmanagerimportdata,metricsfromtorchvisionimportmodels# load manager from checkpointsmanager=DDPMManager.from_checkpoint(...)assertisinstance(manager,DDPMManager),"manager is not a DDPMManager."# initialize datasettesting_dataset:data.Dataset=...# add neccessary metricsinception=models.inception_v3(pretrained=True)inception.fc=torch.nn.Identity()# type: ignoreinception.eval()fid=metrics.FID(inception)manager.metrics.update({"FID":fid})# evaluate the modelsummary=manager.test(testing_dataset,sampling_images=True)Customize Diffusion AlgorithmInheritDiffusionManagerand implement abstract methodsforward_diffusionandsampling_stepto customize the diffusion algorithm.fromdiffusionimportDiffusionManagerclassCustomizedManager(DiffusionManager):defforward_diffusion(self,data:Any,condition:Optional[torch.Tensor]=None,t:Optional[torch.Tensor]=None)->tuple[Any,torch.Tensor]:...defsampling_step(self,data:DiffusionData,i:int,/,*,return_noise:bool=False)->Union[torch.Tensor,tuple[torch.Tensor,torch.Tensor]]:...
Package: torchmasked
torchmaskedTensor operations with mask for PyTorch.Sometimes you need to perform operations on tensors with the masked elements been ignored, for example:>>>input=torch.tensor([1.,2.,3.])>>>result=torch.sum(input)>>>print(result)tensor(6.)>>>mask=torch.tensor([1,1,0]).byte()>>>masked_result=torchmasked.masked_sum(input,mask)>>>print(masked_result)tensor(3.)# element input[2] is masked and ignoredThen this package could be helpful.InstallationFrom source:pipinstallgit+https://github.com/Renovamen/torchmasked.git--upgrade# orpythonsetup.pyinstallSupported Operationsmax (masked version oftorch.max)min (torch.min)sum (torch.sum)mean (torch.mean)softmax (torch.nn.functional.softmaxandtorch.nn.Softmax)LicenseMIT
Package: torchmaxflow
torchmaxflow: Max-flow/Min-cut in PyTorch for 2D images and 3D volumesPytorch-based implementation of Max-flow/Min-cut based on the following paper:Boykov, Yuri, and Vladimir Kolmogorov. "An experimental comparison of min-cut/max-flow algorithms for energy minimization in vision." IEEE transactions on pattern analysis and machine intelligence 26.9 (2004): 1124-1137.If you want same functionality in Numpy, then considerNumpy-based implementationCitationIf you use this code in your research, then please consider citing:Asad, Muhammad, Lucas Fidon, and Tom Vercauteren."ECONet: Efficient Convolutional Online Likelihood Network for Scribble-based Interactive Segmentation."Medical Imaging with Deep Learning (MIDL), 2022.Installation instructionspip install torchmaxflowor# Clone and install from github repo

$ git clone https://github.com/masadcv/torchmaxflow
$ cd torchmaxflow
$ pip install -r requirements.txt
$ python setup.py installExample outputsMaxflow2dInteractive maxflow2dExample usageThe following demonstrates a simple example showing torchmaxflow usage:image=np.asarray(Image.open('data/image2d.png').convert('L'),np.float32)image=torch.from_numpy(image).unsqueeze(0).unsqueeze(0)prob=np.asarray(Image.open('data/image2d_prob.png'),np.float32)prob=torch.from_numpy(prob).unsqueeze(0)lamda=20.0sigma=10.0post_proc_label=torchmaxflow.maxflow(image,prob,lamda,sigma)For more usage examples see:2D and 3D maxflow and interactive maxflow examples:demo_maxflow.pyReferencesOpenCV's Graphcut implementationSimpleCRF's maxflow implementationThis repository depends on the code formaxflow from latest version of OpenCV, which has been included.
Package: torch-max-mem
torch-max-memThis package provides decorators for memory utilization maximization with PyTorch and CUDA by starting with a maximum parameter size and applying successive halving until no more out-of-memory exception occurs.💪 Getting StartedAssume you have a function for batched computation of nearest neighbors using brute-force distance calculation.importtorchdefknn(x,y,batch_size,k:int=3):returntorch.cat([torch.cdist(x[start:start+batch_size],y).topk(k=k,dim=1,largest=False).indicesforstartinrange(0,x.shape[0],batch_size)],dim=0,)Withtorch_max_memyou can decorate this function to reduce the batch size until no more out-of-memory error occurs.importtorchfromtorch_max_memimportmaximize_memory_utilization@maximize_memory_utilization()defknn(x,y,batch_size,k:int=3):returntorch.cat([torch.cdist(x[start:start+batch_size],y).topk(k=k,dim=1,largest=False).indicesforstartinrange(0,x.shape[0],batch_size)],dim=0,)In the code, you can now always pass the largest sensible batch size, e.g.,x=torch.rand(100,100,device="cuda")y=torch.rand(200,100,device="cuda")knn(x,y,batch_size=x.shape[0])🚀 InstallationThe most recent release can be installed fromPyPIwith:$pipinstalltorch_max_memThe most recent code and data can be installed directly from GitHub with:$pipinstallgit+https://github.com/mberr/torch-max-mem.gitTo install in development mode, use the following:$gitclonegit+https://github.com/mberr/torch-max-mem.git
$cdtorch-max-mem
$pipinstall-e.👐 ContributingContributions, whether filing an issue, making a pull request, or forking, are appreciated. SeeCONTRIBUTING.mdfor more information on getting involved.👋 AttributionParts of the logic have been developed withLaurent VermueforPyKEEN.⚖️ LicenseThe code in this package is licensed under the MIT License.🍪 CookiecutterThis package was created with@audreyfeldroy'scookiecutterpackage using@cthoyt'scookiecutter-snekpacktemplate.🛠️ For DevelopersSee developer instrutionsThe final section of the README is for if you want to get involved by making a code contribution.🥼 TestingAfter cloning the repository and installingtoxwithpip install tox, the unit tests in thetests/folder can be
run reproducibly with:$toxAdditionally, these tests are automatically re-run with each commit in aGitHub Action.📖 Building the Documentation$tox-edocs📦 Making a ReleaseAfter installing the package in development mode and installingtoxwithpip install tox, the commands for making a new release are contained within thefinishenvironment
intox.ini. Run the following from the shell:$tox-efinishThis script does the following:UsesBump2Versionto switch the version number in thesetup.cfgandsrc/torch_max_mem/version.pyto not have the-devsuffixPackages the code in both a tar archive and a wheelUploads to PyPI usingtwine. Be sure to have a.pypircfile configured to avoid the need for manual input at this
stepPush to GitHub. You'll need to make a release going with the commit where the version was bumped.Bump the version to the next patch. If you made big changes and want to bump the version by minor, you can
usetox -e bumpversion minorafter.
Package: torchmd
TorchMDAboutTorchMD intends to provide a simple to use API for performing molecular dynamics using PyTorch. This enables researchers to more rapidly do research in force-field development as well as integrate seamlessly neural network potentials into the dynamics, with the simplicity and power of PyTorch.TorchMD uses chemical units consistent with classical MD codes such as ACEMD, namely kcal/mol for energies, K for temperatures, g/mol for masses, and Å for distances.TorchMD is currently WIP so feel free to provide feedback on the API or potential bugs in the GitHub issue tracker.Also check TorchMD-Net for fast and accurate neural network potentialshttps://github.com/torchmd/torchmd-net/CitationPlease cite:@misc{doerr2020torchmd,
      title={TorchMD: A deep learning framework for molecular simulations},
      author={Stefan Doerr and Maciej Majewsk and Adrià Pérez and Andreas Krämer and Cecilia Clementi and Frank Noe and Toni Giorgino and Gianni De Fabritiis},
      year={2020},
      eprint={2012.12106},
      archivePrefix={arXiv},
      primaryClass={physics.chem-ph}
}To reproduce the paper go to the tutorial notebookhttps://github.com/torchmd/torchmd-cg/blob/master/tutorial/Chignolin_Coarse-Grained_Tutorial.ipynbLicenseNote. All the code in this repository is MIT, however we use several file format readers that are taken from Moleculekit which has a free open source non-for-profit, research license. This is mainly in torchmd/run.py. Moleculekit is installed automatically being in the requirement file. Check out Moleculekit here:https://github.com/Acellera/moleculekitInstallationWe recommend installing TorchMD in a new python environment ideally through the Miniforge package manager.mamba create -n torchmd
mamba activate torchmd
mamba install pytorch python=3.10 -c conda-forge
mamba install moleculekit parmed jupyter -c acellera -c conda-forge # For running the examples
pip install torchmdExamplesVarious examples can be found in theexamplesfolder on how to perform dynamics using TorchMD.Help and commentsPlease use the github issue of this repository.AcknowledgementsWe would like to acknowledge funding by the Chan Zuckerberg Initiative and Acellera in support of this project. This project will be now developed in collaboration with openMM (www.openmm.org) and acemd (www.acellera.com/acemd).
Package: torchmd-cg
torchmd-cgInstallationconda create -n torchmd_cg
conda activate torchmd_cg
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
conda install pyyaml ipython scikit-learn tqdm
pip install pytorch-lightning
pip install torchmd-cgUsagepip install moleculekit
conda install seaborn pandas jupyterCheck the jupyter notebook in thetutorialfolder
Package: torchmdo
Multidisciplinary design optimization made fast with PyTorch and modern automatic differentiation.At its heart, torchMDO is a library of optimizers and tools that allow you to build out large-scale
models to assess a design in PyTorch (with its Numpy-like syntax) and to optimize the design extremely quickly by taking
advantage of its automatic differentiation capabilities as well as its GPU acceleration.Also, if you have a model that has previously been built in Python, you can convert it to PyTorch (which is
typically straightforward if it was originally implemented in Numpy) and
you can immediately plug it into torchMDO.Online documentation (and examples):https://torchmdo.readthedocs.io/Installation:Install using pip:pip install torchmdo # minimal install
pip install torchmdo[examples] # to be able to run the examplesTo upgrade to the latest (unstable) version, run:pip install --upgrade git+https://github.com/treforevans/torchmdo.gitSource code repository (and issue tracker):https://github.com/treforevans/torchmdo/License:AGPL-3.0-or-later – see the fileLICENSEfor details.
Package: torchmenu
TorchMenuA simplestreamlitweb application to manage your model deployment withTorchServe. It is designed to tap into your currently deployed TorchServe instance using its APIs.Current features include:View loaded models, including their versions and metricsModel management: load, unload, and delete modelsShow and edit the serverconfig.propertiesfileInstallationpipinstalltorchmenuDevelopmentgitclonehttps://github.com/williamcorsel/TorchMenu.gitcdTorchMenu
pipinstall-e.[dev]pre-commitinstallUsageTo launch the application, run the following command:torchmenu
Package: torch-mfcc
Librosa STFT/Fbank/MFCC in PyTorchAuthor: Shimin ZhangA librosa STFT/Fbank/mfcc feature extration written up in PyTorch using 1D Convolutions.InstallationInstall easily with pip:pip install torch_mfccor download this repo,python setup.py install.UsageIf you want the same timesteps as kaldi, make sure that:the window length, window hop length and fft length are same.set enframed_mode(str)='break', which defaults to 'continue'.set center(bool)=False. which defaults to True.importtorchasthimporttorch.nn.functionalastfimportscipyfromtorch_mfccimportSTFT,FBANK,MFCCimportnumpyasnpimportlibrosadefCalMfcc(signal,sr,fft_len,win_hop,win_len,n_mfcc=13,center=True,dct_type=2,norm='ortho'):spec_amp,n_fft=librosa.spectrum._spectrogram(signal,n_fft=fft_len,hop_length=win_hop,win_length=win_len,center=center,power=2.0,window='hann')mel_basis=librosa.filters.mel(sr,n_fft)S=np.dot(mel_basis,spec_amp)fbank=librosa.core.power_to_db(S,top_db=None)mfcc_spec=scipy.fftpack.dct(fbank,axis=0,type=dct_type,norm=norm)[:n_mfcc]returnspec_amp,fbank,mfcc_specsig=librosa.load(librosa.util.example_audio_file(),duration=10.0,offset=30)[0]device='cpu'sig_th=th.from_numpy(sig)[None,:].float().to(device)fft_len=1024win_hop=256win_len=1024window='hann'n_mel=128n_mfcc=13dct_type=4norm='ortho'center=Falsesr=22050spec_amp,fbank_spec,mfcc_spec=CalMfcc(signal=sig,sr=sr,fft_len=fft_len,win_hop=win_hop,win_len=win_len,n_mfcc=n_mfcc,center=center,dct_type=dct_type,norm=norm)# librosa STFT VS conv_stft# see more test at :https://github.com/echocatzh/conv-stft/blob/master/tests/test_stft.pystft=STFT(win_len=win_len,win_hop=win_hop,fft_len=fft_len,pad_center=center,win_type=window).to(device)real,imag=stft.transform(sig_th,return_type='realimag')spectrum_th=th.square(real)+th.square(imag)print(tf.mse_loss(th.FloatTensor(spec_amp).to(device),spectrum_th.squeeze(0)))# 8.4275e-10# librosa fbank VS torch_fbankfbank=FBANK(win_len,win_hop,fft_len,sr,win_type=window,top_db=None,center=center,n_mel=n_mel).to(device)fbank_spec_th=fbank(sig_th)print(tf.mse_loss(th.FloatTensor(fbank_spec).to(device),fbank_spec_th.transpose(1,2).squeeze(0)))# 1.4462e-09# librosa mfcc VS torch_mfccmfcc=MFCC(win_len,win_hop,fft_len,sr,win_type=window,top_db=None,dct_type=dct_type,norm=norm,center=center,n_mfcc=n_mfcc,n_mel=n_mel).to(device)mfcc_spec_th=mfcc(sig_th)print(tf.mse_loss(th.FloatTensor(mfcc_spec).to(device),mfcc_spec_th.transpose(1,2).squeeze(0)))# 7.2581e-10ContactIf you have any questions, welcome to contact me atshmzhang@npu-aslp.org
Package: torchmimic
MIMIC Benchmark in PyTorchMIMIC Benchmark reimplemented in PyTorch. For examples and documentation checkout:https://torchmimic.readthedocs.io/en/latest/InstallationTo install, run:pip install torchmimicDataThis library contains PyTorch datasets that will load your existing MIMIC Benchmark data. To use those datasets, just import the data you want fromtorchmimic.data:from torchmimic.data import DecompensationDataset
from torchmimic.data import IHMDataset
from torchmimic.data import LOSDataset
from torchmimic.data import PhenotypingDataset
from torchmimic.data import MultitaskDatasetModelsWe've included some of the models used in the benchmark paper for reproduction and comparison with your own methods. Current models include:Standard LSTMYou can access these models fromtorchmimic.models:from torchmimic.models import StandardLSTMBenchmarksEach of the benchmarks can be found intorchmimic.benchmarks:from torchmimic.benchmarks import DecompensationBenchmark
from torchmimic.benchmarks import IHMBenchmark
from torchmimic.benchmarks import LOSBenchmark
from torchmimic.benchmarks import PhenotypingBenchmark
from torchmimic.benchmarks import MultitaskBenchmarkAt a minimum, the benchmark need a model to be trained. You can create the model from one of our existing ones or you can create your own.Weights and Biases SupportThis library has built-in logging of model configurations and key metrics using the Weights and Biases library.TODOsBenchmarksPhenotypingLength of StayDecompensationIn Hospital MortalityMultitaskModelsStandard LSTMStandard LSTM + Deep SupervisionLogistic RegressionChannelwise LSTMChannelwise LSTM + Deep SupervisionMultitask LSTMMultitask Channelwise LSTMTestingTest data for GitHub Workflow