Saravanan666/pypi-org huggingface dataset:
Package: pytorch-merge
PyTorch MergeThis repository contains a script,py_merge.py, that can be used to merge two PyTorch model .bin files into a single model file. This can be useful when you need to combine the weights of two models that have the same architecture and are compatible. The script averages the parameter values of the models for keys that exist in both models.PrerequisitesBefore using this script, make sure you have the following Python packages installed:PyTorchTransformersYou can install them using pip:pip install pytorch_mergeThis will automatically install the dependencies (torchandtransformers).UsageOpen a terminal, and type:pytorch_merge --helpTo get the instructions on how to use it.This tool requires 3 arguments:--config config.json-- The configuration file for the model architecture you are working with.--bin model1.bin model2.bin model3.bin-- All the model’s weights .bin files you want to merge. You can merge weights files of one multiparts model, or weights from different models, in which case weights will be averaged. You can specify as many files as you want, they will be merged one after the others in a loop.--output merged_model.bin-- Where to save the output merged model.For example:pytorch_merge -c config.json -b model1.bin model2.bin -o merged_model.binYou can now use the mergedmerged_model.binfile with your model architecture.Note: Merging models may not always produce the desired results, especially if the models have different architectures or were trained on different data.Use this script only when you are sure that the models are compatible.LicenseThis tool was made by Donalda Feith and is licensed under GNU General Public License v3 or later (GPLv3+).
Package: pytorch-mighty
pytorch-mightyThe Mighty Monitor Trainer for your pytorch models. Powered byVisdom.Documentation:https://pytorch-mighty.readthedocs.io/en/latest/InstallationRequires Python 3.6+InstallPyTorch:CPU backend:conda install pytorch torchvision cpuonly -c pytorchGPU backend:conda install pytorch torchvision cudatoolkit=10.2 -c pytorch$ pip install pytorch-mightyQuick startBefore running any script, start Visdom server:$ python -m visdom.server -port 8097Then runpython examples.pyor use the code below:importtorchimporttorch.nnasnnfromtorchvisionimporttransformsfromtorchvision.datasetsimportMNISTfrommighty.modelsimportMLPfrommighty.monitor.monitorimportMonitorLevelfrommighty.trainerimportTrainerGradfrommighty.utils.dataimportDataLoadermodel=MLP(784,128,10)optimizer=torch.optim.Adam(model.parameters(),lr=1e-3)scheduler=torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer)data_loader=DataLoader(MNIST,transform=transforms.ToTensor())trainer=TrainerGrad(model,criterion=nn.CrossEntropyLoss(),data_loader=data_loader,optimizer=optimizer,scheduler=scheduler)# trainer.restore()  # uncomment to restore the saved statetrainer.monitor.advanced_monitoring(level=MonitorLevel.SIGNAL_TO_NOISE)trainer.train(n_epochs=10,mutual_info_layers=0)Finally, navigate tohttp://localhost:8097to see the training progress.Articles, implemented or reused in the packageFong, R. C., & Vedaldi, A. (2017). Interpretable explanations of black boxes by meaningful perturbation.Paper:https://arxiv.org/abs/1704.03296Used in:trainer/mask.pyBelghazi, M. I., Baratin, A., Rajeswar, S., Ozair, S., Bengio, Y., Courville, A., & Hjelm, R. D. (2018). Mine: mutual information neural estimation.Paper:https://arxiv.org/abs/1801.04062Used in:monitor/mutual_info/neural_estimation.pyKraskov, A., Stögbauer, H., & Grassberger, P. (2004). Estimating mutual information.Paper:https://arxiv.org/abs/1208.4475Used in:monitor/mutual_info/npeet.pyOriginal source code:https://github.com/gregversteeg/NPEETInce, R. A., Giordano, B. L., Kayser, C., Rousselet, G. A., Gross, J., & Schyns, P. G. (2017). A statistical framework for neuroimaging data analysis based on mutual information estimated via a gaussian copula. Human brain mapping, 38(3), 1541-1573.Paper:http://dx.doi.org/10.1002/hbm.23471Used inmonitor/mutual_info/gcmi.pyOriginal source code:https://github.com/robince/gcmiIDTxlpackage to estimate mutual information.Used inmonitor/mutual_info/idtxl.pyProjects that use pytorch-mightyMCMC_BinaryNet- Markov Chain Monte Carlo binary networks optimization.EmbedderSDR- encode images into binary Sparse Distributed Representation (SDR).sparse-representation- Basis Pursuit solvers for the P0- and P1-problems, which encode the data into sparse vectors of high dimensionality.entropy-estimators- estimate Entropy and Mutual Information between multivariate random variables.Check-out more examples onhttp://visdom.kyivaigroup.com:8097/. Give your browser a few minutes to parse the json data.
Package: pytorch-mirror
PyTorch模型、数据集国内镜像一、使用方法只需要在使用模型或数据集之前导入torchmirror.dataset或torchmirror.model模块即可，如下：importtorchimporttorchvision.datasets.mnistasmnistfromtorchmirrorimportdataset,modeltrain_dataset=mnist.MNIST("./data",train=True,download=True)test_dataset=mnist.MNIST("./data",train=False,download=True)二、使用其他镜像要使用其他镜像，只需要修改PYTORCH_MODEL_MIRROR或PYTORCH_DATASET_MIRROR环境变量即可，如下：exportPYTORCH_MODEL_MIRROR=http://192.168.0.100:8080exportPYTORCH_DATASET_MIRROR=http://192.168.0.100:8080
Package: pytorch-mjolnir
Pytorch MjolnirThinking in experiments made simpler for pytorch-lightning.
So that no experiment is wasted and you can iterate faster.On pypi some links are broken ->Visit the project on github.Getting StartedSimply pip installpipinstallpytorch_mjolnirThen read theDocumentationof its API containing also examples.Writing an ExperimentWhen you already have your code split into a model and a loss, it is easy to convert it to a mjolnir experiment.
Simply use the SupervisedExperiment experiment or any of the precanned experiments.
(Learn more in thedocumentation)fromtorch.optimimportAdamfromtorchvision.datasetsimportMNISTfromtorchvisionimporttransformsfromtorch.utils.dataimportrandom_splitfrompytorch_mjolnirimportSupervisedExperimentclassMNISTExperiment(SupervisedExperiment):def__init__(self,learning_rate=1e-3,batch_size=32):super().__init__()self.save_hyperparameters()self.model=MyModel()# Any old pytorch model -> preds = self.model(*features)self.loss=MyLoss()# Any loss -> loss = self.loss(preds, targets)defprepare_data(self):# Prepare the data once (no state allowed due to multi-gpu/node setup.)MNIST(".datasets",train=True,download=True)defload_data(self,stage=None)->Tuple[Any,Any]:# Load your datasets.dataset=MNIST(".datasets",train=True,download=False,transform=transforms.ToTensor())returnrandom_split(dataset,[55000,5000])defconfigure_optimizers(self):# Create an optimizer to your liking.returnAdam(self.parameters(),lr=self.hparams.learning_rate)# Run the experiment when the script is executed.if__name__=="__main__":frompytorch_mjolnirimportrunrun(MNISTExperiment)Running an experimentLocal: Simply run your experiment py file from the command line.
It has lots of parameters to customize its behaviour.pythonexamples/autoencoder.py--name=AutoencoderRemote/SLURM: In a cluster setting check out how the remote run command works, it might make you much more productive. You simply specify arun.template.slurmand arun.template.sh(seeexamples).mjolnir_remoteexamples/autoencoder.py--name=Autoencoder--host=slurm.yourcompany.comContributingCurrently there are no guidelines on how to contribute, so the best thing you can do is open up an issue and get in contact that way.
In the issue we can discuss how you can implement your new feature or how to fix that nasty bug.To contribute, please fork the repositroy on github, then clone your fork. Make your changes and submit a merge request.Origin of the NameMjolnir is thors weapon and a catalyst for lightning. As this library is about being a catalyst for experiments with lightning, the choice.LicenseThis repository is under MIT License. Please see thefull license here.
Package: pytorch-mnl
A simple pytorch based MNL libFit your Multinomial Logistic Regression with PytorchInstallpip install pytorch_mnlHow to useimport the libimportpandasaspdfrompytorch_mnl.coreimport*load datadata=pd.read_csv("./data/Iris.csv").drop("Id",axis=1)choose x, y cols:x_cols=['SepalLengthCm','SepalWidthCm','PetalLengthCm','PetalWidthCm']target_col='Species'the number of classes to predict:n_targets=len(data[target_col].unique())n_targets3X,y=prepare_data(data,x_cols=x_cols,target_col=target_col)we get pytorch tensors ready to use!type(X),type(y)(torch.Tensor, torch.Tensor)let's split in train/valid choosing a percenage as holdout, and choose a batch size to fit our modeldls=DataLoaders.from_Xy(X,y,pct=0.2,batch_size=8)as our model has 4 variables, we will fit a 4 MNL, with 3 targets.model=LinearMNL(len(x_cols),n_targets)learn=Learner(dls,model)learn.fit(25)epoch =   0, val_loss = 2.072, accuracy = 0.53
epoch =   1, val_loss = 1.908, accuracy = 0.53
epoch =   2, val_loss = 1.770, accuracy = 0.80
epoch =   3, val_loss = 1.657, accuracy = 0.80
epoch =   4, val_loss = 1.564, accuracy = 0.80
epoch =   5, val_loss = 1.487, accuracy = 0.80
epoch =   6, val_loss = 1.422, accuracy = 0.80
epoch =   7, val_loss = 1.368, accuracy = 0.80
epoch =   8, val_loss = 1.321, accuracy = 0.80
epoch =   9, val_loss = 1.282, accuracy = 0.83
epoch =  10, val_loss = 1.247, accuracy = 0.83
epoch =  11, val_loss = 1.217, accuracy = 0.83
epoch =  12, val_loss = 1.190, accuracy = 0.83
epoch =  13, val_loss = 1.166, accuracy = 0.83
epoch =  14, val_loss = 1.144, accuracy = 0.87
epoch =  15, val_loss = 1.125, accuracy = 0.87
epoch =  16, val_loss = 1.107, accuracy = 0.90
epoch =  17, val_loss = 1.091, accuracy = 0.90
epoch =  18, val_loss = 1.076, accuracy = 0.90
epoch =  19, val_loss = 1.063, accuracy = 0.90
epoch =  20, val_loss = 1.050, accuracy = 0.90
epoch =  21, val_loss = 1.038, accuracy = 0.90
epoch =  22, val_loss = 1.027, accuracy = 0.90
epoch =  23, val_loss = 1.016, accuracy = 0.90
epoch =  24, val_loss = 1.007, accuracy = 0.90
Package: pytorch-modules
# pytorch_modules## IntroductionA neural network toolkit built on pytorch/opencv/numpy that includes neural network layers, modules, loss functions, optimizers, data loaders, data augmentation, etc.## FeaturesAdvanced neural network modules/loss functions/optimizersUltra-efficient trainer and dataloader that allows you to take full advantage of GPU## Installationsudo pip3 install pytorch_modulesorsudo python3 setup.py install## Usage### pytorch_modules.utilsIncludes a variety of utils for pytorch model training.
See [woodsgao/pytorch_segmentation](https://github.com/woodsgao/pytorch_segmentation) as a tutorial.### pytorch_modules.nnThis module contains a variety of neural network layers, modules and loss functions.import torch
from pytorch_modules.nn import ResBlock# NCHW tensor
inputs = torch.ones([8, 8, 224, 224])
block = ResBlock(8, 16)
outputs = block(inputs)### pytorch_modules.backbonesThis module includes a series of modified backbone networks.import torch
from pytorch_modules.backbones import ResNet# NCHW tensor
inputs = torch.ones([8, 8, 224, 224])
model = ResNet(32)
outputs = model.stages[0](inputs)### pytorch_modules.datasetsThis module includes a series of dataset classes integrated frompytorch_modules.datasets.BasicDatasetwhich is integrated fromtorch.utils.data.Dataset.
The loading method ofpytorch_modules.datasets.BasicDatasetis modified to cache data withLMDBto speed up data loading. This allows your gpu to be fully used for model training without spending a lot of time on data loading and data augmentation.
Please see the corresponding repository for detailed usage.
Package: pytorch-mtcnn
This project is belongs to the original creator (https://github.com/khrlimam/mtcnn-pytorch). I just fixed some problems that may have been caused by newer version of PyTorch. Also this project is available to install from pypi:pip install torch-mtcnnHow to installInstall the package with pip:pip install torch-mtcnnHow to usefromtorch_mtcnnimportdetect_facesfromPILimportImageimage=Image.open('image.jpg')bounding_boxes,landmarks=detect_faces(image)You can use thebounding_boxesto crop the image (assuming there is only 1 face):bounding_boxes=list(map(int,bounding_boxes[0]))img_1=cv2.imread(path)img_1[bounding_boxes[1]:bounding_boxes[3],bounding_boxes[0]:bounding_boxes[2]]AutocropI have included a utility functionget_faces. This function gets the image path and returns all of the faces in the image:fromtorch_mtcnnimportget_facesfaces=get_faces('img.jpg')RequirementsPlease see therequirements.txtCreditThe original project belongs tohttps://github.com/khrlimam/mtcnn-pytorch.
Package: pytorch-multilabel-balanced-sampler
PyTorch Multilabel Balanced SamplersThis package provides samplers to fetch data samples from multilabel datasets in a balanced manner. Balanced sampling from multilabel datasets can be especially useful to handle class imbalance issues.SamplersBaseMultilabelBalancedRandomSampler: This is the base class for all the provided samplers. It initializes the basic structure required for sampling, such as class indices.RandomClassSampler: This sampler randomly chooses a class and then picks a random example from that class.ClassCycleSampler: As the name suggests, it cycles through each class and fetches a random example from the current class.LeastSampledClassSampler: Chooses the class with the least number of samples fetched so far and retrieves a random example from that class.UsageInstallation:This package is installable via pip:pipinstallpytorch-multilabel-balanced-samplerInitialization:For all samplers, the initialization arguments are:labels: A 2D tensor of shape(n_examples, n_classes)containing the one-hot encoded labels for the dataset.indices: A sequence of integers representing the indices of the dataset. Default is the range of the dataset size.frompytorch_multilabel_balanced_sampler.samplersimportRandomClassSampler,ClassCycleSampler,LeastSampledClassSamplersampler1=RandomClassSampler(labels=my_labels,indices=my_indices)sampler2=ClassCycleSampler(labels=my_labels)sampler3=LeastSampledClassSampler(labels=my_labels,indices=my_indices)Fetching samples:Iterate over the sampler object to fetch samples:forsampleinsampler1:print(sample)Note:All samplers are inherited fromBaseMultilabelBalancedRandomSampler, which in turn inherits from PyTorch'sSamplerclass. This ensures compatibility with PyTorch's data loading utilities.LicenseThe MIT License (MIT).LicenseFeedback & IssuesFor feedback, issues, or feature requests, please raise an issue on the GitHub repository.
Package: pytorch-nanopi
专门针对nanopi开发版编译的pytorch安装包在root权限下pip install pytorch_nanopi若出现错误，使用源码包安装源码地址https://github.com/NocoldBob/pytorch/nanogit clonehttps://github.com/NocoldBob/pytorch/nano编译需求cmake>=3.10python setup.py build安装后在/usr/……/torch/路径下，cp _C.…… ，_dl.…… ,修改文件名为_C.so _dl.so并打开torch/__init__.py文件下第107行到111行代码的注释有问题请发邮件，不定时查看，不定时解决问题
Package: pytorch-nemo
NEMO (NEural Minimizer for pytOrch)NEMO (NEural Minimizer for pytOrch)is a small library for minimization of Deep Neural Networks developed in PyTorch, aimed at their deployment on ultra-low power, highly memory constrained platforms, in particular (but not exclusively) PULP-based microcontrollers.
NEMO features include:deployment-related transformations such as BatchNorm folding, bias removal, weight equalizationcollection of statistics on activations and weightspost-training quantizationquantization-aware fine-tuning, with partially automated precision relaxationmixed-precision quantizationbit-accurate deployment modelexport to ONNXNEMO operates on three different "levels" of quantization-aware DNN representations, all built upontorch.nn.Moduleandtorch.autograd.Function:fake-quantizedFQ: replaces regular activations (e.g., ReLU) with quantization-aware ones (PACT) and dynamically quantized weights (with linear PACT-like quantization), maintaining full trainability (similar to the native PyTorch support, but not based on it).quantized-deployableQD: replaces all function with deployment-equivalent versions, trading off trainability for a more accurate representation of numerical behavior on real hardware.integer-deployableID: replaces all activation and weight tensors used along the network with integer-based ones. It aims at bit-accurate representation of actual hardware behavior.
All the quantized representations support mixed-precision weights (signed and asymmetric) and activations (unsigned). The current version of NEMO targets per-layer quantization; work on per-channel quantization is in progress.NEMO is organized as a Python library that can be applied with relatively small changes to an existing PyTorch based script or training framework.Installation and requirementsThe NEMO library currently supports PyTorch >= 1.3.1 and runs on Python >= 3.5.
To install it from PyPI, just run:pip install pytorch-nemoYou can also install a development (and editable) version of NEMO by directly downloading this repo:git clone https://github.com/pulp-platform/nemo
cd nemo
pip install -e .Then, you can import it in your script usingimport nemoExampleMNIST post-training quantization:https://colab.research.google.com/drive/1AmcITfN2ELQe07WKQ9szaxq-WSu4hdQbDocumentationFull documentation for NEMO is under development (seedocfolder). You can find a technical report covering the deployment-aware quantization methodology here:https://arxiv.org/abs/2004.05930LicenseNEMO is released under Apache 2.0, see the LICENSE file in the root of this repository for details.AcknowledgementsNEMO is an outcome of the European CommissionHorizon 2020 ALOHA Project, funded under the EU's Horizon 2020 Research and Innovation Programme, grant agreement no. 780788.
Package: pytorch-ner
Named Entity Recognition (NER) with PyTorchPipeline for trainingNERmodels usingPyTorch.ONNXexport supported.UsageInstead of writing custom code for specific NER task, you just need:install pipeline:pipinstallpytorch-nerrun pipeline:either interminal:pytorch-ner-train--path_to_configconfig.yamlor inpython:importpytorch_nerpytorch_ner.train(path_to_config="config.yaml")ConfigThe user interface consists of only one fileconfig.yaml.Change it to create the desired configuration.Defaultconfig.yaml:torch:device:'cpu'seed:42data:train_data:path:'data/conll2003/train.txt'sep:''lower:trueverbose:truevalid_data:path:'data/conll2003/valid.txt'sep:''lower:trueverbose:truetest_data:path:'data/conll2003/test.txt'sep:''lower:trueverbose:truetoken2idx:min_count:1add_pad:trueadd_unk:truedataloader:preprocess:truetoken_padding:'<PAD>'label_padding:'O'percentile:100batch_size:256model:embedding:embedding_dim:128rnn:rnn_unit:LSTM# GRU, RNNhidden_size:256num_layers:1dropout:0bidirectional:trueoptimizer:optimizer_type:Adam# torch.optimclip_grad_norm:0.1params:lr:0.001weight_decay:0amsgrad:falsetrain:n_epoch:10verbose:truesave:path_to_folder:'models'export_onnx:trueNOTE: to export trained model toONNXuse the following config parameter:save:
  export_onnx: trueData FormatPipeline works with text file containing separated tokens and labels on each line. Sentences are separated by empty line.
Labels should already be in necessary format, e.g. IO, BIO, BILUO, ...Example:token_11    label_11
token_12    label_12

token_21    label_21
token_22    label_22
token_23    label_23

...OutputAfter training the model, the pipeline will return the following files:model.pth- pytorch NER modelmodel.onnx- onnx NER model (optional)token2idx.json- mapping from token to its indexlabel2idx.json- mapping from label to its indexconfig.yaml- config that was used to train the modellogging.txt- logging fileModelsList of implemented models:BiLTSMBiLTSMCRFBiLTSMAttnBiLTSMAttnCRFBiLTSMCNNBiLTSMCNNCRFBiLTSMCNNAttnBiLTSMCNNAttnCRFEvaluationAll results are obtained on CoNLL-2003dataset. We didn't search the best parameters.ModelTrain F1-weightedValidation F1-weightedTest F1-weightedBiLSTM0.9680.9280.876RequirementsPython >= 3.6CitationIf you usepytorch_nerin a scientific publication, we would appreciate references to the following BibTex entry:@misc{dayyass2020ner,author={El-Ayyass, Dani},title={Pipeline for training NER models using PyTorch},howpublished={\url{https://github.com/dayyass/pytorch_ner}},year={2020}}TODO: docker cuda
Package: pytorch-nn-tools
Tools for NN creation with Pytorch. The project is greatly inspired by fast.ai library.
The project brings the convenience functions from fast.ai to a usual pytorch user.Usage examplesCheckpointSaverfrompytorch_nn_tools.devicesimportto_devicefrompytorch_nn_tools.train.checkpointimportCheckpointSavercheckpoint_saver=CheckpointSaver(path_checkpoints,logger=DummyLogger())# create your model, optimizer, scheduler# train for several epochsforepochinrange(100):.....# at the end of each epoch we save the resultscheckpoint_saver.save(model,optimizer,scheduler,epoch)# later you can load the latest checkpoint and continue traininglast=checkpoint_saver.find_last(start_epoch,end_epoch)iflastisnotNone:print(f"found pretrained results for epoch{last}. Loading...")self.checkpoint_saver.load(model,optimizer,scheduler,last)else:print(f"pretrained weights are not found")MiscFree software: MIT licenseDocumentation:https://pytorch-nn-tools.readthedocs.io.
Package: pytorch-partial-crf
pytorch-partial-crfPartial/Fuzzy conditional random field in PyTorch.Document:https://pytorch-partial-crf.readthedocs.io/How to useInstallpipinstallpytorch-partial-crfUse CRFimporttorchfrompytorch_partial_crfimportCRF# Createnum_tags=6model=CRF(num_tags)batch_size,sequence_length=3,5emissions=torch.randn(batch_size,sequence_length,num_tags)tags=torch.LongTensor([[1,2,3,3,5],[1,3,4,2,1],[1,0,2,4,4],])# Computing negative log likelihoodmodel(emissions,tags)Use partial CRFimporttorchfrompytorch_partial_crfimportPartialCRF# Createnum_tags=6model=PartialCRF(num_tags)batch_size,sequence_length=3,5emissions=torch.randn(batch_size,sequence_length,num_tags)# Set unknown tag to -1tags=torch.LongTensor([[1,2,3,3,5],[-1,3,3,2,-1],[-1,0,-1,-1,4],])# Computing negative log likelihoodmodel(emissions,tags)Use Marginal CRFimporttorchfrompytorch_partial_crfimportMarginalCRF# Createnum_tags=6model=MarginalCRF(num_tags)batch_size,sequence_length=3,5emissions=torch.randn(batch_size,sequence_length,num_tags)# Set probability tagsmarginal_tags=torch.Tensor([[[0.2,0.2,0.2,0.1,0.1,0.2],[0.8,0.0,0.0,0.1,0.1,0.0],[0.0,0.0,0.0,0.0,1.0,0.0],[0.3,0.0,0.0,0.1,0.6,0.0],],[[0.2,0.2,0.2,0.1,0.1,0.2],[0.8,0.0,0.0,0.1,0.1,0.0],[0.0,0.0,0.0,0.0,1.0,0.0],[0.3,0.0,0.0,0.1,0.6,0.0],],[[0.2,0.2,0.2,0.1,0.1,0.2],[0.8,0.0,0.0,0.1,0.1,0.0],[0.0,0.0,0.0,0.0,1.0,0.0],[0.3,0.0,0.0,0.1,0.6,0.0],],])# Computing negative log likelihoodmodel(emissions,marginal_tags)DecodingViterbi decodemodel.viterbi_decode(emissions)Restricted viterbi decodepossible_tags=torch.randn(batch_size,sequence_length,num_tags)possible_tags[possible_tags<=0]=0# `0` express that can not pass.possible_tags[possible_tags>0]=1# `1` express that can pass.possible_tags=possible_tags.byte()model.restricted_viterbi_decode(emissions,possible_tags)Marginal probabilitiesmodel.marginal_probabilities(emissions)ContributingWe welcome contributions! Please post your requests and comments on Issue.LicenseMITReferencesThe implementation is based on AllenNLP CRF module and pytorch-crf.