Skip to content

Commit

Permalink
Published new version
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCappelletti94 committed Jul 16, 2020
1 parent 1e68505 commit 0c5e822
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 191 deletions.
Binary file added dist/keras_bed_sequence-1.1.3.tar.gz
Binary file not shown.
191 changes: 1 addition & 190 deletions keras_bed_sequence.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: keras-bed-sequence
Version: 1.1.2
Version: 1.1.3
Summary: Lazily one-hot encoding bed sequences using Keras Sequence.
Home-page: https://github.com/LucaCappelletti94/keras_bed_sequence
Author: Luca Cappelletti
Expand Down Expand Up @@ -28,195 +28,6 @@ Description: keras_bed_sequence

|coveralls| |sonar_coverage| |code_climate_coverage|

Usage examples
------------------------
The following examples are tested within the package test suite.

Classification task example
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Let's start by building an extremely simple classification task model:

.. code:: python

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten
from keras_mixed_sequence import MixedSequence

model = Sequential([
Flatten(),
Dense(1)
])
model.compile(
optimizer="nadam",
loss="MSE"
)

We then proceed to load the training data into Keras Sequences,
using, in particular, a MixedSequence object:

.. code:: python

import numpy as np
from keras_mixed_sequence import MixedSequence
from keras_bed_sequence import BedSequence

batch_size = 32
bed_sequence = BedSequence(
"hg19",
"path/to/bed/files.bed",
batch_size
)
y = the_output_values
mixed_sequence = MixedSequence(
x=bed_sequence,
y=y,
batch_size=batch_size
)

Finally, we can proceed to use the obtained MixedSequence
to train our model:

.. code:: python

model.fit(
mixed_sequence,
steps_per_epoch=mixed_sequence.steps_per_epoch,
epochs=2,
verbose=0,
shuffle=True
)

Auto-encoding task example
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Let's start by building an extremely simple auto-encoding task model:

.. code:: python

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, Reshape, Conv2DTranspose

model = Sequential([
Reshape((200, 4, 1)),
Conv2D(16, kernel_size=3, activation="relu"),
Conv2DTranspose(1, kernel_size=3, activation="relu"),
Reshape((-1, 200, 4))
])
model.compile(
optimizer="nadam",
loss="MSE"
)

We then proceed to load the training data into Keras Sequences,
using, in particular, a MixedSequence object:

.. code:: python

import numpy as np
from keras_mixed_sequence import MixedSequence
from keras_bed_sequence import BedSequence

batch_size = 32
bed_sequence = BedSequence(
Genome("hg19", chromosomes=["chr1"]),
"path/to/bed/files.bed",
batch_size
)
mixed_sequence = MixedSequence(
x=bed_sequence,
y=bed_sequence,
batch_size=batch_size
)

Finally, we can proceed to use the obtained MixedSequence
to train our model:

.. code:: python

model.fit(
mixed_sequence,
steps_per_epoch=mixed_sequence.steps_per_epoch,
epochs=2,
verbose=0,
shuffle=True
)

Multi-task example (classification + auto-encoding)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Let's start by building an extremely simple multi-tasks model:

.. code:: python

from tensorflow.keras.models import Model
from tensorflow.keras.layers import Dense, Conv2D, Reshape, Flatten, Conv2DTranspose, Input

inputs = Input(shape=(200, 4))

flattened = Flatten()(inputs)

output1 = Dense(
units=1,
activation="relu",
name="output1"
)(flattened)

hidden = Reshape((200, 4, 1))(inputs)
hidden = Conv2D(16, kernel_size=3, activation="relu")(hidden)
hidden = Conv2DTranspose(1, kernel_size=3, activation="relu")(hidden)
output2 = Reshape((200, 4), name="output2")(hidden)

model = Model(
inputs=inputs,
outputs=[output1, output2],
name="my_model"
)

model.compile(
optimizer="nadam",
loss="MSE"
)

We then proceed to load the training data into Keras Sequences,
using, in particular, a MixedSequence object:

.. code:: python

import numpy as np
from keras_mixed_sequence import MixedSequence
from keras_bed_sequence import BedSequence

batch_size = 32
bed_sequence = BedSequence(
"hg19",
"{cwd}/test.bed".format(
cwd=os.path.dirname(os.path.abspath(__file__))
),
batch_size
)
y = np.random.randint(
2,
size=(bed_sequence.samples_number, 1)
)
mixed_sequence = MixedSequence(
bed_sequence,
{
"output1": y,
"output2": bed_sequence
},
batch_size
)

Finally, we can proceed to use the obtained MixedSequence
to train our model:

.. code:: python

model.fit(
mixed_sequence,
steps_per_epoch=mixed_sequence.steps_per_epoch,
epochs=2,
verbose=0,
shuffle=True
)


.. |travis| image:: https://travis-ci.org/LucaCappelletti94/keras_bed_sequence.png
Expand Down
1 change: 1 addition & 0 deletions keras_bed_sequence.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ keras_bed_sequence.egg-info/dependency_links.txt
keras_bed_sequence.egg-info/requires.txt
keras_bed_sequence.egg-info/top_level.txt
keras_bed_sequence/utils/__init__.py
keras_bed_sequence/utils/fast_to_categorical.py
keras_bed_sequence/utils/nucleotides_to_numbers.py
2 changes: 1 addition & 1 deletion keras_bed_sequence/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Current version of package keras_bed_sequence"""
__version__ = "1.1.2"
__version__ = "1.1.3"

0 comments on commit 0c5e822

Please sign in to comment.