pileoffeather


Namepileoffeather JSON
Version 0.4.2 PyPI version JSON
download
home_pagehttps://github.com/usedToBeTomas/pile-of-feather
SummaryLightweight and easy to use ml library for small projects, create a neural network in minutes.
upload_time2023-12-06 22:17:01
maintainer
docs_urlNone
authorDaniele Tomaselli
requires_python>=3.6
licenseMIT
keywords neural network ml ai machine learning simple nn
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
<h1>pile of feather</h1>
<img src="https://github.com/usedToBeTomas/pile-of-feather/blob/main/images/pof2.jpeg" width="400" height="400" />

Pileoffeather is not an alternative to big ml library like pytorch or tensorflow, it lacks features and optimization, such as gpu support. The goal is to create a lightweight library of about 100 lines of code that is easy to use and quick to implement for creating small projects or experiment with ml.

<h3>

[Documentation](https://github.com/usedToBeTomas/pile-of-feather#documentation) | [Examples](https://github.com/usedToBeTomas/pile-of-feather#examples)

</h3>

</div>

Install module
```cmd
pip install pileoffeather
```
# Examples
## examples/image_classifier
Handwritten digit image classifier, dataset is made out of 500 images of ones and 500 images of zeros taken from the mnist dataset. The first code snippet is defining the neural network model, uploading the dataset and than training the model
```python
from pileoffeather import nn, data_loader
import numpy as np

#Create neural network model
model = nn.create(name = "test1", layers = [[400, 'input'], [30, 'relu'], [10, 'relu'], [1, 'sigmoid']])

#Load and prepare dataset
ones = data_loader.load(data_type = "image", color = "grayscale", folder = "ones", resize = (20,20))
zeros = data_loader.load(data_type = "image", color = "grayscale", folder = "zeros", resize = (20,20))
input = np.vstack((ones, zeros))
output = np.concatenate((np.ones(500), np.zeros(500)))

#Train the neural network and save the model
nn.mbgd(model, input, output, batch_size = 16, epoch_number = 10, rate = 0.6)
```
This second code snippet is used to run the trained model
```python
from pileoffeather import nn, data_loader

#Load neural network model
model = nn.load(name = "test1")

#Load example input image
input = data_loader.loadImage("example_image_one.png", (20,20), "grayscale")

#Run the neural network model
output = model.run(input)
print(output)
```

---

# Documentation
The module consists of 3 files: nn.py (create and train nn), data_loader.py (for loading and converting data) and engine.py (Hidden core neural network engine < 100 lines of code).
## nn.py - neural network module

```python
#Import module
from pileoffeather import nn

#Define neural network model, the available activation functions are "sigmoid","relu","leakyRelu"
model = nn.create(name = "test1", layers = [[400,""],[50,"relu"],[10,"relu"],[1,"sigmoid"]])

#Load an exsisting model
model = nn.load(name = "test1")

#Mini-batch gradient descent, parallel backprop execution on each run of the mini-batch
nn.mbgd(model, input_matrix, output_matrix, batch_size = 16, epoch_number = 100, rate = 0.03)

#Save the model
model.save()

#Use the neural network
output = model.run(input)

#Compute single mini_batch pass, model.computeBatch(batch_input, batch_output, batch_size, learning_rate)
model.computeBatch(batch_input, batch_output, 16, 0.3)

#Pop a layer out of the neural network model (ex. remove layer at index 2)
model.pop(2)

#Insert a model layers over an other model, training is preserved (ex. at index 2)
model.insert(model1,2)
```

## data_loader.py - data load module

```python
#Import module
from pileoffeather import data_loader

#Load dataset of images from local folder
dataset = data_loader.load(data_type = "image", color = "grayscale", folder = "folder_name_containing_all_images", resize = (20,20))

#Load training input data of mnist, normalize input from 0 to 1 using divide = 255
dataset = data_loader.load(data_type = "gz", path = "train-images-idx3-ubyte.gz", start_index = 16, input_number = 784, divide = 255)

#Load training output data of mnist, use one_hot encoding to convert a decimal number to an array
#4 -> [0,0,0,0,1,0,0,0,0,0] 0 -> [1,0,0,0,0,0,0,0,0,0]
dataset = data_loader.load(data_type = "gz", path = "train-labels-idx1-ubyte.gz", start_index = 8, one_hot = 10)

#Load a single image to feed the neural network loadImage(name, resize, color)
input = data_loader.loadImage("example_image.png", (20,20), "grayscale")

#Convert neural network output to image and save, saveImage(neural_network_output, image_path, resize, color)
data_loader.saveImage(neural_network_output, "image_path_and_name", (20,20), "grayscale")
```

---

### TODO
- Add audio support on data_loader.py
- Add recurrent neural networks and common architectures like transformer or gan
- Possibility to live graph loss, accuracy or similar stats during training

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/usedToBeTomas/pile-of-feather",
    "name": "pileoffeather",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "neural network,ml,ai,machine learning,simple,nn",
    "author": "Daniele Tomaselli",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/03/75/e872ea31aa100c65de444ed65acf282fda772d930d5afd76e197478fbea0/pileoffeather-0.4.2.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\r\n<h1>pile of feather</h1>\r\n<img src=\"https://github.com/usedToBeTomas/pile-of-feather/blob/main/images/pof2.jpeg\" width=\"400\" height=\"400\" />\r\n\r\nPileoffeather is not an alternative to big ml library like pytorch or tensorflow, it lacks features and optimization, such as gpu support. The goal is to create a lightweight library of about 100 lines of code that is easy to use and quick to implement for creating small projects or experiment with ml.\r\n\r\n<h3>\r\n\r\n[Documentation](https://github.com/usedToBeTomas/pile-of-feather#documentation) | [Examples](https://github.com/usedToBeTomas/pile-of-feather#examples)\r\n\r\n</h3>\r\n\r\n</div>\r\n\r\nInstall module\r\n```cmd\r\npip install pileoffeather\r\n```\r\n# Examples\r\n## examples/image_classifier\r\nHandwritten digit image classifier, dataset is made out of 500 images of ones and 500 images of zeros taken from the mnist dataset. The first code snippet is defining the neural network model, uploading the dataset and than training the model\r\n```python\r\nfrom pileoffeather import nn, data_loader\r\nimport numpy as np\r\n\r\n#Create neural network model\r\nmodel = nn.create(name = \"test1\", layers = [[400, 'input'], [30, 'relu'], [10, 'relu'], [1, 'sigmoid']])\r\n\r\n#Load and prepare dataset\r\nones = data_loader.load(data_type = \"image\", color = \"grayscale\", folder = \"ones\", resize = (20,20))\r\nzeros = data_loader.load(data_type = \"image\", color = \"grayscale\", folder = \"zeros\", resize = (20,20))\r\ninput = np.vstack((ones, zeros))\r\noutput = np.concatenate((np.ones(500), np.zeros(500)))\r\n\r\n#Train the neural network and save the model\r\nnn.mbgd(model, input, output, batch_size = 16, epoch_number = 10, rate = 0.6)\r\n```\r\nThis second code snippet is used to run the trained model\r\n```python\r\nfrom pileoffeather import nn, data_loader\r\n\r\n#Load neural network model\r\nmodel = nn.load(name = \"test1\")\r\n\r\n#Load example input image\r\ninput = data_loader.loadImage(\"example_image_one.png\", (20,20), \"grayscale\")\r\n\r\n#Run the neural network model\r\noutput = model.run(input)\r\nprint(output)\r\n```\r\n\r\n---\r\n\r\n# Documentation\r\nThe module consists of 3 files: nn.py (create and train nn), data_loader.py (for loading and converting data) and engine.py (Hidden core neural network engine < 100 lines of code).\r\n## nn.py - neural network module\r\n\r\n```python\r\n#Import module\r\nfrom pileoffeather import nn\r\n\r\n#Define neural network model, the available activation functions are \"sigmoid\",\"relu\",\"leakyRelu\"\r\nmodel = nn.create(name = \"test1\", layers = [[400,\"\"],[50,\"relu\"],[10,\"relu\"],[1,\"sigmoid\"]])\r\n\r\n#Load an exsisting model\r\nmodel = nn.load(name = \"test1\")\r\n\r\n#Mini-batch gradient descent, parallel backprop execution on each run of the mini-batch\r\nnn.mbgd(model, input_matrix, output_matrix, batch_size = 16, epoch_number = 100, rate = 0.03)\r\n\r\n#Save the model\r\nmodel.save()\r\n\r\n#Use the neural network\r\noutput = model.run(input)\r\n\r\n#Compute single mini_batch pass, model.computeBatch(batch_input, batch_output, batch_size, learning_rate)\r\nmodel.computeBatch(batch_input, batch_output, 16, 0.3)\r\n\r\n#Pop a layer out of the neural network model (ex. remove layer at index 2)\r\nmodel.pop(2)\r\n\r\n#Insert a model layers over an other model, training is preserved (ex. at index 2)\r\nmodel.insert(model1,2)\r\n```\r\n\r\n## data_loader.py - data load module\r\n\r\n```python\r\n#Import module\r\nfrom pileoffeather import data_loader\r\n\r\n#Load dataset of images from local folder\r\ndataset = data_loader.load(data_type = \"image\", color = \"grayscale\", folder = \"folder_name_containing_all_images\", resize = (20,20))\r\n\r\n#Load training input data of mnist, normalize input from 0 to 1 using divide = 255\r\ndataset = data_loader.load(data_type = \"gz\", path = \"train-images-idx3-ubyte.gz\", start_index = 16, input_number = 784, divide = 255)\r\n\r\n#Load training output data of mnist, use one_hot encoding to convert a decimal number to an array\r\n#4 -> [0,0,0,0,1,0,0,0,0,0] 0 -> [1,0,0,0,0,0,0,0,0,0]\r\ndataset = data_loader.load(data_type = \"gz\", path = \"train-labels-idx1-ubyte.gz\", start_index = 8, one_hot = 10)\r\n\r\n#Load a single image to feed the neural network loadImage(name, resize, color)\r\ninput = data_loader.loadImage(\"example_image.png\", (20,20), \"grayscale\")\r\n\r\n#Convert neural network output to image and save, saveImage(neural_network_output, image_path, resize, color)\r\ndata_loader.saveImage(neural_network_output, \"image_path_and_name\", (20,20), \"grayscale\")\r\n```\r\n\r\n---\r\n\r\n### TODO\r\n- Add audio support on data_loader.py\r\n- Add recurrent neural networks and common architectures like transformer or gan\r\n- Possibility to live graph loss, accuracy or similar stats during training\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Lightweight and easy to use ml library for small projects, create a neural network in minutes.",
    "version": "0.4.2",
    "project_urls": {
        "Homepage": "https://github.com/usedToBeTomas/pile-of-feather"
    },
    "split_keywords": [
        "neural network",
        "ml",
        "ai",
        "machine learning",
        "simple",
        "nn"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0375e872ea31aa100c65de444ed65acf282fda772d930d5afd76e197478fbea0",
                "md5": "44fb60c974a39ae33035b010dc48725e",
                "sha256": "519de77e29a56155cfe0d64bfc39017a30c0734e76397819318bfe88b4b873a0"
            },
            "downloads": -1,
            "filename": "pileoffeather-0.4.2.tar.gz",
            "has_sig": false,
            "md5_digest": "44fb60c974a39ae33035b010dc48725e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 6446,
            "upload_time": "2023-12-06T22:17:01",
            "upload_time_iso_8601": "2023-12-06T22:17:01.029618Z",
            "url": "https://files.pythonhosted.org/packages/03/75/e872ea31aa100c65de444ed65acf282fda772d930d5afd76e197478fbea0/pileoffeather-0.4.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-06 22:17:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "usedToBeTomas",
    "github_project": "pile-of-feather",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pileoffeather"
}
        
Elapsed time: 0.34175s