Saravanan666/pypi-org huggingface dataset:
Package: torchsaber
torchsaber: Elegant Dimensions for a more Civilized AgeIt is a period of civil war. Rebel spaceships have won their first victory
against the awesomeRuntimeError(experimental support for Named Tensors
in
PyTorch).MotivationHow often have you written or seen code like this?images=torch.randn(10,3,64,64)flipped=images.transpose(2,3)cropped=flipped[:,:,x:x+32,y:y+32]flatten=cropped.view(-1,32*32)gray=flatten.sum(dim=2)/3.or gotten a mysterious error likeRuntimeError:Thesizeoftensorx(2)mustmatchthesizeoftensory(4)atnon-singletondimension2I don't care what universe you're from, that's got to hurt your eyes. What do
all those numbers mean? What order are the dimensions in by the end? Isdim=2the right summation to average the channels? Who knows? Unnamed
dimensions lead to anger; anger leads to bugs; bugs lead to suffering.But, a ray of hope!PyTorch hasreleasedexperimental support fornamed tensors:that is, tensors whose dimensions
have names rather than simply numeric indices. It's wonderful news, but it
still has some rough edges. For example, you have to refer to names using
hardcoded string literals everywhere; a typo (e.g.'hieght') can break your
code in unexpected ways that aren't caught at runtime.torchsaberis aminimal syntactic sugar for named tensors. Its goal is to
give you power (unlimited power!) by allowing all manipulation of dimensions to
be doneby namerather than by numeric indices or hardcoded string literals.
Dimensions and their manipulations arefirst-classobjectsthat interface cleanly with PyTorch's user-facing API. For example, the above
code snippet becomes:fromtorchsaberimportdimsbatch,channel,height,width,features=dims('batch','channel','height','width','features')images=torch.randn|batch(10)+channel(3)+height(64)+width(64)flipped=images.permute(~width,~height)cropped=flipped|height[:32]+width[:32]flatten=cropped.flatten([~height,~width],~features)gray=flatten.sum(dim=~channel)/3.By "minimal" I mean the entire implementation is around 100 lines of code.Can I use it?Sure! The easiest way to learn is to read the big comment at the top oftorchsaber.py. It's a literate doctest! Thenpip install torch torchvision torchsaberandfrom torchsaber import dimsand enjoy. torchsaber tries to be
compatible withthe named tensor
docsand
should work with operatorssupportedby named tensors.However, because named tensors are experimental, so is torchsaber. Therealgoal of the project is to provoke some discussion around human-friendly designs
for the tensor programs of the future.(Some!) referencesHere's a non-exhaustive list of prior work (many of these have their own
bibliographies you can follow)…Tensors Considered HarmfulandPart 2, which led to named tensor support in PyTorch.An older PyTorch named tensor proposalTypesafe Abstractions for Tensor Operations(SCALA 2017)Other projects with similar goals:datarrayxarraytsalibMoreto say, have you?Open an issue, file a PR, send me an email!
Package: torchsample
Lightweight pytorch functions for neural network featuremap sampling.WARNING: API is not yet stable. API subject to change!IntroductionSampling neural network featuremaps at explicit coordinates has become more and more common with popular
developments like:Learning Continuous Image Representation with Local Implicit Image FunctionNeRF: Representing Scenes as Neural Radiance Fields for View SynthesisPointRend: Image Segmentation as RenderingPyTorch provides the tools necessary that to sample coordinates, but they result in a large amount of error-prone code.
TorchSample intends to make it simple so you can focus on other parts of the model.UsageInstallationRequires python>=3.8Installtorchsamplevia pip:pipinstalltorchsampleOr, if you want to install the nightly version:pipinstallgit+https://github.com/BrianPugh/torchsample.git@mainTrainingA common scenario is to randomly sample points from a featmap and
from the ground truth.importtorchsampleastsb,c,h,w=batch["image"].shapecoords=ts.coord.rand(b,4096,2)# (b, 4096, 2) where the last dim is (x, y)featmap=feature_extractor(batch["image"])# (b, feat, h, w)sampled=ts.sample(coords,featmap)# (b, 4096, feat)gt_sample=ts.sample(coords,batch["gt"])InferenceDuring inference, a comprehensive query of the network to form a complete
image is common.importtorchimporttorchsampleastsb,c,h,w=batch["image"].shapecoords=ts.coord.full_like(batch["image"])featmap=encoder(batch["image"])# (b, feat, h, w)feat_sampled=ts.sample(coords,featmap)# (b, h, w, c)output=model(featmap)# (b, h, w, pred)output=output.permute(0,3,1,2)Positional EncodingCommon positional encoding schemes are available.importtorchsampleastscoords=ts.coord.rand(b,4096,2)pos_enc=ts.encoding.gamma(coords)A common task it concatenating the positional encoding to
sampled values. You can do this by passing a callable intots.sample:importtorchsampleastsencoder=ts.encoding.Gamma()sampled=ts.sample(coords,featmap,encoder=encoder)Modelstorchsamplehas some common builtin models:importtorchsampleasts# Properly handles (..., feat) tensors.model=ts.models.MLP(256,256,512,512,1024,1024,1)Design Decisionsalign_corners=Falseby default (same as Pytorch).
You should probably not touch it;explanation here.Everything is in normalized coordinates[-1,1]by default.Coordinates are always in order(x, y,...).Whenever a size is given, it will be in(w, h)order;
i.e. matches coordinate order. It makes implementation simpler
and a consistent rule helps prevent bugs.Whencoordsis a function argument, it comes first.Simple wrapper functions (likets.coord.rand) are
provided to make the intentions of calling code more clear.Try and mimic nativepytorchandtorchvisioninterfaces as
much as possible.Try and make the common-usecase as simple and intuitive as possible.
Package: torchsampler
Imbalanced Dataset SamplerIntroductionIn many machine learning applications, we often come across datasets where some types of data may be seen more than other types. Take identification of rare diseases for example, there are probably more normal samples than disease ones. In these cases, we need to make sure that the trained model is not biased towards the class that has more data. As an example, consider a dataset where there are 5 disease images and 20 normal images. If the model predicts all images to be normal, its accuracy is 80%, and F1-score of such a model is 0.88. Therefore, the model has high tendency to be biased toward the ‘normal’ class.To solve this problem, a widely adopted technique is called resampling. It consists of removing samples from the majority class (under-sampling) and / or adding more examples from the minority class (over-sampling). Despite the advantage of balancing classes, these techniques also have their weaknesses (there is no free lunch). The simplest implementation of over-sampling is to duplicate random records from the minority class, which can cause overfitting. In under-sampling, the simplest technique involves removing random records from the majority class, which can cause loss of information.In this repo, we implement an easy-to-use PyTorch samplerImbalancedDatasetSamplerthat is able torebalance the class distributions when sampling from the imbalanced datasetestimate the sampling weights automaticallyavoid creating a new balanced datasetmitigate overfitting when it is used in conjunction with data augmentation techniquesUsageFor a simple start install the package via one of following ways:pipinstalltorchsamplerSimply pass anImbalancedDatasetSamplerfor the parametersamplerwhen creating aDataLoader.
For example:fromtorchsamplerimportImbalancedDatasetSamplertrain_loader=torch.utils.data.DataLoader(train_dataset,sampler=ImbalancedDatasetSampler(train_dataset),batch_size=args.batch_size,**kwargs)Then in each epoch, the loader will sample the entire dataset and weigh your samples inversely to your class appearing probability.Example: Imbalanced MNIST DatasetDistribution of classes in the imbalanced dataset:With Imbalanced Dataset Sampler:(left: test acc in each epoch; right: confusion matrix)Without Imbalanced Dataset Sampler:(left: test acc in each epoch; right: confusion matrix)Note that there are significant improvements for minor classes such as269, while the accuracy of the other classes is preserved.ContributingWe appreciate all contributions. If you are planning to contribute back bug-fixes, please do so without any further discussion. If you plan to contribute new features, utility functions or extensions, please first open an issue and discuss the feature with us.LicensingMIT licensed.
Package: torchsat
TorchSat is an open-source deep learning framework for satellite imagery analysis based on PyTorch.This project is still work in progress. If you want to know more about it, please refer to theRoadmap.Hightlight:wink: Support multi-channels(> 3 channels, e.g. 8 channels) images and TIFF file as input.:yum: Convenient data augmentation method for classification, sementic segmentation and object detection.:heart_eyes: Lots of models for satellite vision tasks, such as ResNet, DenseNet, UNet, PSPNet, SSD, FasterRCNN ...:smiley: Lots of common satellite datasets loader.:open_mouth: Training script for common satellite vision tasks.Installpython3 setup.py installHow to useIntroduction-Classification tutorial-Data augmentation-data-augmentation.ipynbData loadermodelstrain scriptFeaturesData augmentationWe suppose all the input images, masks and bbox should be NumPy ndarray. The data shape should be[height, width]or[height, width, channels].pixel levelPixel-level transforms only change the input image and will leave any additional targets such as masks, bounding boxes unchanged. It support all channel images. Some transforms only support specific input channles.TransformImagemasksBBoxesToTensor✓✓✓Normalize✓✓✓ToGray✓✓✓GaussianBlur✓✓✓RandomNoise✓✓✓RandomBrightness✓✓✓RandomContrast✓✓✓spatial-levelSpatial-level transforms will simultaneously change both an input image as well as additional targets such as masks, bounding boxes. It support all channel images.TransformImagemasksBBoxesResize✓✓✓Pad✓✓✓RandomHorizontalFlip✓✓✓RandomVerticalFlip✓✓✓RandomFlip✓✓✓CenterCrop✓✓✓RandomCrop✓✓✓RandomResizedCrop✓✓✓ElasticTransform✓✓RandomRotation✓✓RandomShift✓✓ModelsClassificationAll models support multi-channels as input (e.g. 8 channels).VGG:vgg11,vgg11_bn,vgg13,vgg13_bn,vgg16,vgg16_bn,vgg19_bn,vgg19ResNet:resnet18,resnet34,restnet50,resnet101,resnet152DenseNet:densenet121,densenet169,densenet201,densenet161Inception:inception_v3MobileNet:mobilenet_v2Sementic SegmentationUNet:unet,unet34,unet101,unet152(with resnet as backbone.)DataloaderClassificationSAT-4 and SAT-6 airborne datasetsEuroSatPatternNetNWPU_redisc45ShowcaseIf you extend this repository or build projects that use it, we'd love to hear from you.ReferencetorchvisionNoteIf you are looking for the torchvision-enhance, please checkout theenhancebranch. But it was deprecated.
Package: torchsde-brownian
torchsde_brownianThis library provides the Brownian motion generation code fromtorchsdeversion 0.2.5
as a standalone packagetorchsde_brownian.It is mainly meant for use in downstream packages such ask-diffusionanddiffusers,
for where it is a drop-in replacement: the dependency just needs to be changed,
and the import fortorchsdetotorchsde_brownian.According to the authors oftorchsde, that package is currently in maintenance mode,
so no further development, aside from possible compatibility fixes, is expected.All credit for the original implementation goes to the authors oftorchsde,
Xuechen Li and Patrick Kidger.The commit history of this repository has been kept intact so as to preserve
the provenance of the code and their contributions.Installationpipinstalltorchsde_brownianRequirements:Python >=3.8 and PyTorch >=1.6.0.DocumentationAvailablehere.Citation and referencesPlease find citations and references intorchsde's readme.
Package: torchsenti
TorchSentiSentiment Analysis Library for Research with PyTorchTorchSenti provides sentiment analysis datasets from a simple one (positive/negative labels) to fine-grained one (aspect-based). TorchSenti is compatible with PyTorch to develop model and use pre-trained model to benchmark your work with other researchers.Features- Text Cleansing e.g removing hyperlinks
- WordPiece Tokenization with tagging for aspect extraction
- Entity metrics for aspect detectionDataset Available- **Sentiment Analysis**
    - IMDB Movie Reviews
    - Pros and Cons
    - Movie Review
    - Trip Advisor
    - City Search Data
    - Yelp Review
- **Aspect-based Sentiment Analysis**
    - SemEval 2014 Task 4 (ToDo)
    - SemEval 2015 Task 12 (ToDo)
    - SemEval 2016 Task 5 (ToDo)InstallationYou can install TorchSenti using pippip install torchsentifrom sourcegit clone https://github.com/jakartaresearch/pytorch-sentiment.git
    cd pytorch-sentiment
    python setup.py installGetting StartedContributors
Package: torch-sentiment
IntroductionBeta release, api subject to change. Install with:pip install torch-sentimentThis repo contains Neural Nets written with the pytorch framework for sentiment analysis.A LSTM based torch model can be found in the rnn folder. In spite of large language models (GPT3.5 as of 2023)
dominating the conversation, small models can be pretty effective and are nice to learn from. This model focuses on sentiment analysis and was trained on
a single gpu in minutes and requires less than 1GB of memory.Usage# where 0 is very negative and 1 is very positive
from torch_sentiment.tokenizer import get_trained_tokenizer
from torch_sentiment.rnn.model import get_trained_model

model = get_trained_model(64)
tokenizer = get_trained_tokenizer()
review_text = "greatest pie ever, best in town!"
positive_ids = tokenizer.tokenize_text(review_text)
model.predict(positive_ids)
  
>> tensor(0.9701)Install for development with miniconda:conda create -n {env}  
conda install pip  
pip install -e .Retrain modelTo rerun the model:get the yelpdataset,get the glove 6B 100Ddatasetplace both files in the package data directoryrun the training script in workflows
Package: torchservant
TorchServant is an assembly helping quickly development for PyTorch users.It contains following components:
modelservant:   Manage weights files and checkpoints, keep training process continuous.
procmonitor:            API for visdom and tensorboard, visualize diagrams, illustrations and progresses.
stats           Resource statistics on GPUs, memories, cpu, and consumed time.
classicmodels:  Include AlexNet, VGG, Resnet, Inception, etc.
visualfeature:  Visualize feature maps during training and evaluation process.
weightransfer:  An Qt-based visual tool to transfer weights between different models.
Package: torchserve
TorchServe is a flexible and easy to use tool for
servingPyTorchmodels in production.Use the TorchServe CLI, or the pre-configured Docker images, to start a
service that sets up HTTP endpoints to handle model inference requests.InstallationFull installation instructions are in the project repo:https://github.com/pytorch/serve/blob/master/README.mdSource codeYou can check the latest source code as follows:git clone https://github.com/pytorch/serve.gitCitationIf you use torchserve in a publication or project, please cite torchserve:https://github.com/pytorch/serve
Package: torchserve-ag
TorchServe is a flexible and easy to use tool for
servingPyTorchmodels in production.Use the TorchServe CLI, or the pre-configured Docker images, to start a
service that sets up HTTP endpoints to handle model inference requests.InstallationFull installation instructions are in the project repo:https://github.com/pytorch/serve/blob/master/README.mdSource codeYou can check the latest source code as follows:git clone https://github.com/pytorch/serve.gitCitationIf you use torchserve in a publication or project, please cite torchserve:https://github.com/pytorch/serve
Package: torchserve-client
TorchServe Python ClientInstallpipinstalltorchserve_clientUsageUsingtorchserve_clientis a breeze! It has support for both REST APIs
and gRPC APIs.REST ClientTo make calls to REST endpoint, simply initialize aTorchServeClientRESTobject as shown below:fromtorchserve_clientimportTorchServeClientREST# Initialize the REST TorchServeClient objectts_client=TorchServeClientREST()ts_clientTorchServeClient(base_url=http://localhost, management_port=8081, inference_port=8080)If you wish to customize thebase URL,management port, orinference portof your TorchServe server, you can pass them as
arguments during initialization:fromtorchserve_clientimportTorchServeClientREST# Customize the base URL, management port, and inference portts_client=TorchServeClientREST(base_url='http://your-torchserve-server.com',management_port=8081,inference_port=8080)ts_clientTorchServeClient(base_url=http://your-torchserve-server.com, management_port=8081, inference_port=8080)gRPC ClientTo create a gRPC client, simply create aTorchServeClientGRPCobjectfromtorchserve_clientimportTorchServeClientGRPC# Initialize the gRPC TorchServeClient objectts_client=TorchServeClientGRPC()ts_clientTorchServeClientGRPC(base_url=localhost, management_port=7071, inference_port=7070)To customize base URL and default ports, pass them as arguments during
initializationfromtorchserve_clientimportTorchServeClientGRPC# Initialize the gRPC TorchServeClient objectts_client=TorchServeClientGRPC(base_url='http://your-torchserve-server.com',management_port=7071,inference_port=7070)ts_clientTorchServeClientGRPC(base_url=your-torchserve-server.com, management_port=7071, inference_port=7070)With these intuitive APIs at your disposal, you can harness the full
power of the Management and Inference API and take your application to
next level. Happy inferencing! 🚀🔥
Package: torchserve-dashboard
Torchserve DashboardTorchserve Dashboard using StreamlitRelated blogpostUsageAdditional Requirement:torchserve(recommended:v0.5.3, supports: v0.6.0)Simply run:pip3installtorchserve-dashboard--user# torchserve-dashboard [streamlit_options(optional)] -- [config_path(optional)] [model_store(optional)] [log_location(optional)] [metrics_location(optional)]torchserve-dashboard#OR change porttorchserve-dashboard--server.port8105----config_path./torchserve.properties#OR provide a custom configurationtorchserve-dashboard----config_path./torchserve.properties--model_store./model_store:exclamation: Keep in mind that If you change any of the--config_path,--model_store,--metrics_location,--log_locationoptions while there is a torchserver already running before starting torch-dashboard they won't come into effect until you stop&start torchserve. These options are used instead of their respective environment variablesTS_CONFIG_FILE, METRICS_LOCATION, LOG_LOCATION.ORgitclonehttps://github.com/cceyda/torchserve-dashboard.git
streamlitruntorchserve_dashboard/dash.py#ORstreamlitruntorchserve_dashboard/dash.py--server.port8105----config_path./torchserve.propertiesExample torchserveconfig:inference_address=http://127.0.0.1:8443
management_address=http://127.0.0.1:8444
metrics_address=http://127.0.0.1:8445
grpc_inference_port=7070
grpc_management_port=7071
number_of_gpu=0
batch_size=1
model_store=./model_storeIf the server doesn't start for some reason check if your ports are already in use!Updates[15-oct-2020] addscale workerstab[16-feb-2021] (functionality) make logpath configurable,(functionality)remove model_name requirement,(UI)add cosmetic error messages[10-may-2021] update config & make it optional. update streamlit. Auto create folders[31-may-2021] Update to v0.4 (Add workflow API) Refactor out streamlit from api.py.[30-nov-2021] Update to v0.5, adding support forencrypted model serving(not tested). Update streamlit to v1+FAQsDoes torchserver keep running in the background?The torchserver is spawned usingPopenand keeps running in the background even if you stop the dashboard.What about environment variables?These environment variables are passed to the torchserve command:ENVIRON_WHITELIST=["LD_LIBRARY_PATH","LC_CTYPE","LC_ALL","PATH","JAVA_HOME","PYTHONPATH","TS_CONFIG_FILE","LOG_LOCATION","METRICS_LOCATION","AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_DEFAULT_REGION"]How to change the logging format of torchserve?You can set the location of your custom log4j2 config in your configuration file as inherevmargs=-Dlog4j.configurationFile=file:///path/to/custom/log4j2.xmlWhat is the meaning behind the weird versioning?The minor follows the compatible torchserve version, patch version reflects the dashboard versioningHelp & Question & FeedbackOpen an issueTODOsAsync?Better loggingRemote only mode
Package: torchserve-nightly
TorchServe is a flexible and easy to use tool for
servingPyTorchmodels in production.Use the TorchServe CLI, or the pre-configured Docker images, to start a
service that sets up HTTP endpoints to handle model inference requests.InstallationFull installation instructions are in the project repo:https://github.com/pytorch/serve/blob/master/README.mdSource codeYou can check the latest source code as follows:git clone https://github.com/pytorch/serve.gitCitationIf you use torchserve in a publication or project, please cite torchserve:https://github.com/pytorch/serve
Package: torch-sgld
SGLD in PyTorchThis package implementsSGLDandcSGLDas aPyTorch Optimizer.InstallationInstall frompipas:pipinstalltorch-sgldTo install the latest directly from source, runpipinstallgit+https://github.com/activatedgeek/torch-sgld.gitUsageThe general idea is to modify the usual gradient-based update loops
in PyTorch with theSGLDoptimizer.fromtorch_sgldimportSGLDf=module()## construct PyTorch nn.Module.sgld=SGLD(f.parameters(),lr=lr,momentum=.9)## Add momentum to make it SG-HMC.sgld_scheduler=## Optionally add a step-size scheduler.for_inrange(num_steps):energy=f()energy.backward()sgld.step()sgld_scheduler.step()## Optional scheduler step.cSGLDcan be implemented by using a cyclical learning rate schedule.
See thetoy_csgld.ipynbnotebook for a
complete example.LicenseApache 2.0
Package: torchshape
TorchshapeCalculates the output shape of Pytorch operationsHow to use:Install torchshape package:pip install torchshapeImport torchshape package:from torchshape import tensorshapeCall tensorshape function in your code:outshape = tensorshape(op, inshape)where op is a torch.nn operation (see thelistof supported operations), inshape and outshape are tuples.Seelenet.pyfor example usage.List of supported operationsnn.Conv2dnn.Linearnn.MaxPool2dnn.AvgPool2dnn.Flatten