keras_mixed_sequence
=========================================================================================
|pip| |downloads|
Lazily loading mixed sequences using Keras Sequence,
focused on multi-task models.
How do I install this package?
----------------------------------------------
As usual, just download it using pip:
.. code:: shell
pip install keras_mixed_sequence
Usage examples
----------------------------------------------
Example for traditional single-task models
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
First of all let's create a simple single-task model:
.. code:: python
from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Sequential
model = Sequential([
Dense(1, activation="relu")
])
model.compile(
optimizer="nadam",
loss="relu"
)
Then we proceed to load or otherwise create the training data.
Here there will be listed, in the future, some custom
Sequence objects that have been created for the purpose
of being used alongside this library.
.. code:: python
X = either_a_numpy_array_or_sequence_for_input
y = either_a_numpy_array_or_sequence_for_output
Now we combine the training data using the MixedSequence
object.
.. code:: python
from keras_mixed_sequence import MixedSequence
sequence = MixedSequence(
X, y,
batch_size=batch_size
)
Finally, we can train the model:
.. code:: python
from multiprocessing import cpu_count
model.fit_generator(
sequence,
steps_per_epoch=sequence.steps_per_epoch,
epochs=2,
verbose=0,
use_multiprocessing=True,
workers=cpu_count(),
shuffle=True
)
Example for multi-task models
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
First of all let's create a simple multi-taks model:
.. code:: python
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Dense, Input
inputs = Input(shape=(10,))
output1 = Dense(
units=10,
activation="relu",
name="output1"
)(inputs)
output2 = Dense(
units=10,
activation="relu",
name="output2"
)(inputs)
model = Model(
inputs=inputs,
outputs=[output1, output2],
name="my_model"
)
model.compile(
optimizer="nadam",
loss="MSE"
)
Then we proceed to load or otherwise create the training data.
Here there will be listed, in the future, some custom
Sequence objects that have been created for the purpose
of being used alongside this library.
.. code:: python
X = either_a_numpy_array_or_sequence_for_input
y1 = either_a_numpy_array_or_sequence_for_output1
y2 = either_a_numpy_array_or_sequence_for_output2
Now we combine the training data using the MixedSequence
object.
.. code:: python
from keras_mixed_sequence import MixedSequence
sequence = MixedSequence(
x=X,
y={
"output1": y1,
"output2": y2
},
batch_size=batch_size
)
Finally, we can train the model:
.. code:: python
from multiprocessing import cpu_count
model.fit_generator(
sequence,
steps_per_epoch=sequence.steps_per_epoch,
epochs=2,
verbose=0,
use_multiprocessing=True,
workers=cpu_count(),
shuffle=True
)
.. |pip| image:: https://badge.fury.io/py/keras-mixed-sequence.svg
:target: https://badge.fury.io/py/keras-mixed-sequence
:alt: Pypi project
.. |downloads| image:: https://pepy.tech/badge/keras-mixed-sequence
:target: https://pepy.tech/badge/keras-mixed-sequence
:alt: Pypi total project downloads
Raw data
{
"_id": null,
"home_page": "https://github.com/LucaCappelletti94/keras_mixed_sequence",
"name": "keras-mixed-sequence",
"maintainer": "",
"docs_url": null,
"requires_python": ">3.5.2",
"maintainer_email": "",
"keywords": "",
"author": "Luca Cappelletti",
"author_email": "cappelletti.luca94@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/26/97/0f66d9fa1579eaded44a0c572c8e2e9d2daa89f5d911d45f0307e8d2be73/keras_mixed_sequence-1.0.29.tar.gz",
"platform": null,
"description": "keras_mixed_sequence\n=========================================================================================\n|pip| |downloads|\n\nLazily loading mixed sequences using Keras Sequence,\nfocused on multi-task models.\n\nHow do I install this package?\n----------------------------------------------\nAs usual, just download it using pip:\n\n.. code:: shell\n\n pip install keras_mixed_sequence\n\n\nUsage examples\n----------------------------------------------\n\nExample for traditional single-task models\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nFirst of all let's create a simple single-task model:\n\n.. code:: python\n\n from tensorflow.keras.layers import Dense\n from tensorflow.keras.models import Sequential\n\n model = Sequential([\n Dense(1, activation=\"relu\")\n ])\n model.compile(\n optimizer=\"nadam\",\n loss=\"relu\"\n )\n\nThen we proceed to load or otherwise create the training data.\nHere there will be listed, in the future, some custom\nSequence objects that have been created for the purpose\nof being used alongside this library.\n\n.. code:: python\n\n X = either_a_numpy_array_or_sequence_for_input\n y = either_a_numpy_array_or_sequence_for_output\n\nNow we combine the training data using the MixedSequence\nobject.\n\n.. code:: python\n\n from keras_mixed_sequence import MixedSequence\n\n sequence = MixedSequence(\n X, y,\n batch_size=batch_size\n )\n\nFinally, we can train the model:\n\n.. code:: python\n\n from multiprocessing import cpu_count\n\n model.fit_generator(\n sequence,\n steps_per_epoch=sequence.steps_per_epoch,\n epochs=2,\n verbose=0,\n use_multiprocessing=True,\n workers=cpu_count(),\n shuffle=True\n )\n\n\nExample for multi-task models\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nFirst of all let's create a simple multi-taks model:\n\n.. code:: python\n\n from tensorflow.keras.models import Model\n from tensorflow.keras.layers import Dense, Input\n\n inputs = Input(shape=(10,))\n\n output1 = Dense(\n units=10,\n activation=\"relu\",\n name=\"output1\"\n )(inputs)\n output2 = Dense(\n units=10,\n activation=\"relu\",\n name=\"output2\"\n )(inputs)\n\n model = Model(\n inputs=inputs,\n outputs=[output1, output2],\n name=\"my_model\"\n )\n\n model.compile(\n optimizer=\"nadam\",\n loss=\"MSE\"\n )\n\nThen we proceed to load or otherwise create the training data.\nHere there will be listed, in the future, some custom\nSequence objects that have been created for the purpose\nof being used alongside this library.\n\n.. code:: python\n\n X = either_a_numpy_array_or_sequence_for_input\n y1 = either_a_numpy_array_or_sequence_for_output1\n y2 = either_a_numpy_array_or_sequence_for_output2\n\nNow we combine the training data using the MixedSequence\nobject.\n\n.. code:: python\n\n from keras_mixed_sequence import MixedSequence\n\n sequence = MixedSequence(\n x=X,\n y={\n \"output1\": y1,\n \"output2\": y2\n },\n batch_size=batch_size\n )\n\nFinally, we can train the model:\n\n.. code:: python\n\n from multiprocessing import cpu_count\n\n model.fit_generator(\n sequence,\n steps_per_epoch=sequence.steps_per_epoch,\n epochs=2,\n verbose=0,\n use_multiprocessing=True,\n workers=cpu_count(),\n shuffle=True\n )\n\n\n.. |pip| image:: https://badge.fury.io/py/keras-mixed-sequence.svg\n :target: https://badge.fury.io/py/keras-mixed-sequence\n :alt: Pypi project\n\n.. |downloads| image:: https://pepy.tech/badge/keras-mixed-sequence\n :target: https://pepy.tech/badge/keras-mixed-sequence\n :alt: Pypi total project downloads\n\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Lazily loading mixed sequences using Keras Sequence, focused on multi-task models.",
"version": "1.0.29",
"project_urls": {
"Homepage": "https://github.com/LucaCappelletti94/keras_mixed_sequence"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "26970f66d9fa1579eaded44a0c572c8e2e9d2daa89f5d911d45f0307e8d2be73",
"md5": "f284371a3bb9e306af1e5bed60dbd9d9",
"sha256": "4d49f4325988dccd9d1f6d1ea53e1fc0be8a4479545387f79db7d9245ed66e91"
},
"downloads": -1,
"filename": "keras_mixed_sequence-1.0.29.tar.gz",
"has_sig": false,
"md5_digest": "f284371a3bb9e306af1e5bed60dbd9d9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">3.5.2",
"size": 7056,
"upload_time": "2024-02-03T09:40:32",
"upload_time_iso_8601": "2024-02-03T09:40:32.918073Z",
"url": "https://files.pythonhosted.org/packages/26/97/0f66d9fa1579eaded44a0c572c8e2e9d2daa89f5d911d45f0307e8d2be73/keras_mixed_sequence-1.0.29.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-03 09:40:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "LucaCappelletti94",
"github_project": "keras_mixed_sequence",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "keras-mixed-sequence"
}