torchy


Nametorchy JSON
Version 0.1.2 PyPI version JSON
download
home_page
SummaryA pytorch wrapper that makes .fit() (and others) possible in nn.Module!
upload_time2023-01-28 11:36:06
maintainer
docs_urlNone
authorAshim Dahal
requires_python>=3.6
licenseMIT 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.
keywords deep learning pytorch tensorflow torch
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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 ready to be used in everyday code and is in a beta stage as of today. After additional checks and testing, torchy will be passed as stable.</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. 

<i>It's recommended to have python version >=3.6 and <=3.8, although no problems have yet been encountered in 3.9, and 3.10.</i>

Use pypi's pip to install torchy.
``` 
pip install torchy 
```
or
```
pip3 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`.
```py
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.

```py
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)
# Now you have a trained model and can also access model.hist attribute
print(model.hist)
```
You can also use a dataloader instead of a dataset. 
```python
# Use a DataLoader instead of a TensorDataSet
dataloader = DataLoader(dataset, batch_size = 2)
model = model.fit(dataloader, loss_fn,opt,20)
```
If you're using a dataloader and want to do validation while running .fit()
after every epochs, you will have to manually pass valid_dataloader.


`torchy.utils.data` can also be used to put your dataloader into a device and split your dataset.
```py
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](https://github.com/ashimdahal/torchy/blob/master/docs/README.md).

## To-do
0. More testing

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

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "torchy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "Deep Learning,PyTorch,Tensorflow,Torch",
    "author": "Ashim Dahal",
    "author_email": "codeashim@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/02/fd/322e5e43994439a33c05c9c1ec6c6d7882ea7a06be331bfab0103f27dab2/torchy-0.1.2.tar.gz",
    "platform": null,
    "description": "# Welcome to torchy\nThe 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.\nWe aim to retain every functionality of PyTorch, while keeping them native, and also add our piece of functionality.\n\n<b>The aim of torchy is to enhance the experience of Pytorch and not to replace it. torchy is ready to be used in everyday code and is in a beta stage as of today. After additional checks and testing, torchy will be passed as stable.</b>\n## Introduction\ntorchy is a PyTorch wrapper that has some additional benefits to using plain pytorch. With torchy you have everything in pytorch plus\nsome additional features found on other libraries. The main separating factor between torchy and torchfit or 100s of other pytorch-like\nmodules that exists is that you don't have to re-learn to use the pytorch module.\n\ntorchy is a wrapper build on top of pytorch which enables you to use your existing code on pyTorch and still have the added benefits.\n## Installation using pip\nIt'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. \n\n<i>It's recommended to have python version >=3.6 and <=3.8, although no problems have yet been encountered in 3.9, and 3.10.</i>\n\nUse pypi's pip to install torchy.\n``` \npip install torchy \n```\nor\n```\npip3 install torchy\n```\n\nPS: 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.\n## Additional Functionality\nDefine a model using nn.Module just like with regular pyTorch but `import torchy.nn` instead of `torch.nn`.\n```py\nimport torchy.nn as nn\n\n\nclass Model(nn.Module):\n    def __init__(self):\n        super().__init__()\n        self.linear = nn.Linear(1, 1)\n\n    def forward(self,x):\n        return self.linear(x)\n\n\nmodel = Model()\n```\nNow you can use torchy's functionality.\n\n```py\nimport torch\nfrom torchy.utils.data import TensorDataset, DataLoader\n\n# prepare dummy data\nx = torch.tensor([[12.],[13],[15]])\ny = torch.tensor([[2.],[3],[4]])\ndataset = TensorDataset(x,y)\n\n# nn is still same (torchy.nn)\nloss_fn = nn.functional.mse_loss\nopt = torch.optim.SGD(model.parameters(), lr=0.001, momentum=.9)\n# Use mode.fit() to fit the model in the given TensorDataset\nmodel = model.fit(dataset, loss_fn, opt, epochs=20, valid_pct=25, batch_size=2)\n# Now you have a trained model and can also access model.hist attribute\nprint(model.hist)\n```\nYou can also use a dataloader instead of a dataset. \n```python\n# Use a DataLoader instead of a TensorDataSet\ndataloader = DataLoader(dataset, batch_size = 2)\nmodel = model.fit(dataloader, loss_fn,opt,20)\n```\nIf you're using a dataloader and want to do validation while running .fit()\nafter every epochs, you will have to manually pass valid_dataloader.\n\n\n`torchy.utils.data` can also be used to put your dataloader into a device and split your dataset.\n```py\nfrom torchy.utils.data import DeviceDL, SplitPCT\n# put dataloader in appropirate device\ndevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\ndataloader = DeviceDL(dataloader)\n\n# Split the dataset\ndataset = SplitPCT(dataset)\ntrain_ds, valid_ds = dataset.train_ds, dataset.valid_ds\n```\n\nAdditional features like get_loss(), _accuracy() and full documentation, user guide, best practices and tutorials to use torchy can be found in the [docs](https://github.com/ashimdahal/torchy/blob/master/docs/README.md).\n\n## To-do\n0. More testing\n\nFeel free to contribute your code and drop a star on the project if you liked the idea.",
    "bugtrack_url": null,
    "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.",
    "summary": "A pytorch wrapper that makes .fit() (and others) possible in nn.Module!",
    "version": "0.1.2",
    "split_keywords": [
        "deep learning",
        "pytorch",
        "tensorflow",
        "torch"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "362f0b841d6d454d80fba5d1d43f791cf90b5e746afd65b47bf4a893b9498539",
                "md5": "bd37fa112d0be1aa43eab08bb4fdc368",
                "sha256": "8cd981bb458fcbf9a30a0a95d473b8523cbab07d90010108f0226c1afaae1db7"
            },
            "downloads": -1,
            "filename": "torchy-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bd37fa112d0be1aa43eab08bb4fdc368",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 9291,
            "upload_time": "2023-01-28T11:36:01",
            "upload_time_iso_8601": "2023-01-28T11:36:01.551887Z",
            "url": "https://files.pythonhosted.org/packages/36/2f/0b841d6d454d80fba5d1d43f791cf90b5e746afd65b47bf4a893b9498539/torchy-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "02fd322e5e43994439a33c05c9c1ec6c6d7882ea7a06be331bfab0103f27dab2",
                "md5": "84985be276e30e3afc62041f3ac2c4da",
                "sha256": "a62fb98ad4c09d9d40fb0f1ed143987f05ec5506154bdf0b2c6d1b32a4a4d3ad"
            },
            "downloads": -1,
            "filename": "torchy-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "84985be276e30e3afc62041f3ac2c4da",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 11616,
            "upload_time": "2023-01-28T11:36:06",
            "upload_time_iso_8601": "2023-01-28T11:36:06.963514Z",
            "url": "https://files.pythonhosted.org/packages/02/fd/322e5e43994439a33c05c9c1ec6c6d7882ea7a06be331bfab0103f27dab2/torchy-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-28 11:36:06",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "torchy"
}
        
Elapsed time: 0.05517s