Metadata-Version: 2.1
Name: torchy
Version: 0.0.2
Summary: A pytorch wrapper that makes .fit() (and others) possible in nn.Module!
Project-URL: repository, https://github.com/ashimdahal/easy-torch.git
Project-URL: changelog, https://github.com/me/spam/blob/master/CHANGELOG.md
Author: Ashim Dahal
Author-email: codeashim@gmail.com
License: MIT License
        
        Copyright (c) 2023 Ashim  Dahal
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE.txt
Keywords: Deep Learning,PyTorch,Tensorflow,Torch
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.8
Requires-Dist: torch>=1.12.1
Description-Content-Type: text/markdown

# Welcome to torchy
The aim of this project is to create a PyTorch wrapper that wraps the torch.nn.Module and has additional data preprocessing utilities on torch.utils.data.
We aim to retain every functionality of PyTorch, while keeping them native, and also add our piece of functionality.

<b>The aim of torchy is to enhance the experience of Pytorch and not to replace it. torchy is currently a work in progress and will be going through constant changes everyday.</b>
## Introduction
torchy is a PyTorch wrapper that has some additional benefits to using plain pytorch. With torchy you have everything in pytorch plus
some additional features found on other libraries. The main separating factor between torchy and torchfit or 100s of other pytorch-like
modules that exists is that you don't have to re-learn to use the pytorch module.

torchy is a wrapper build on top of pytorch which enables you to use your existing code on pyTorch and still have the added benefits.
## Installation using pip
It's a good idea to have PyTroch preinstalled on your current virtual environment. See [official guide](https://pytorch.org/get-started/locally/) to install PyTorch. 
<br>
> pip install torchy

PS: PyTorch will be atuomatically installed to your environment if you already don't have it but it's recommended to install it using the official guide.
## Additional Functionality
Define a model using nn.Module just like with regular pyTorch but `import torchy.nn` instead of `torch.nn`.
```python
import torchy.nn as nn


class Model(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(1, 1)

    def forward(self,x):
        return self.linear(x)


model = Model()
```
Now you can use torchy's functionality.

```python
import torch
from torchy.utils.data import TensorDataset, DataLoader

# prepare dummy data
x = torch.tensor([[12.],[13],[15]])
y = torch.tensor([[2.],[3],[4]])
dataset = TensorDataset(x,y)

# nn is still same (torchy.nn)
loss_fn = nn.functional.mse_loss
opt = torch.optim.SGD(model.parameters(), lr=0.001, momentum=.9)
# Use mode.fit() to fit the model in the given TensorDataset
model = model.fit(dataset, loss_fn, opt, epochs=20, valid_pct=25, batch_size=2)
```
You can also use a dataloader instead of a dataset. If you're using a dataloader be sure to pass additional argument "valid_dataloader" otherwise 
the no model validation would be carried out.

```python
# Use a DataLoader instead of a TensorDataSet
dataloader = DataLoader(dataset, batch_size = 2)
model = model.fit(dataloader, loss_fn,opt,20)
```

`torchy.utils.data` can also be used to put your dataloader into a device and split your dataset.
```python
from torchy.utils.data import DeviceDL, SplitPCT
# put dataloader in appropirate device
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
dataloader = DeviceDL(dataloader)

# Split the dataset
dataset = SplitPCT(dataset)
train_ds, valid_ds = dataset.train_ds, dataset.valid_ds
```

Additional features like get_loss(), _accuracy() and full documentation, user guide, best practices and tutorials to use torchy can be found in the [docs](docs/README.md).

## To-do

0. Documentation
1. Docstring
2. More testing

Feel free to contribute your code and drop a star on the project if you liked the idea.