Commit 063c87b3 authored by lucas_miranda's avatar lucas_miranda
Browse files

Excluded debug regions from coverage report - added code climate template to .gitlab-ci.yml

parent 0a3615ad
......@@ -12,7 +12,7 @@ test:
- pip install -r ./deepof/requirements.txt
- pip install -e deepof/
- coverage run --source deepof -m pytest
- coverage report -m --include deepof/utils.py,deepof/preprocess.py,deepof/model_utils.py,deepof/visuals.py,deepof/models.py
- coverage report -m --include deepof/utils.py,deepof/preprocess.py,deepof/model_utils.py,deepof/visuals.py,deepof/models.py,deepof/hypermodels.py
- coverage xml -o deepof_cov.xml
artifacts:
reports:
......
......@@ -14,7 +14,7 @@ from tensorflow.keras import Input, Model, Sequential
from tensorflow.keras.activations import softplus
from tensorflow.keras.callbacks import LambdaCallback
from tensorflow.keras.constraints import UnitNorm
from tensorflow.keras.initializers import he_uniform, Orthogonal, RandomNormal
from tensorflow.keras.initializers import he_uniform, Orthogonal
from tensorflow.keras.layers import BatchNormalization, Bidirectional
from tensorflow.keras.layers import Dense, Dropout, LSTM
from tensorflow.keras.layers import RepeatVector, Reshape, TimeDistributed
......@@ -29,11 +29,15 @@ tfpl = tfp.layers
class SEQ_2_SEQ_AE(HyperModel):
"""Hyperparameter tuning pipeline for deepof.models.SEQ_2_SEQ_AE"""
def __init__(self, input_shape):
super().__init__()
self.input_shape = input_shape
def build(self, hp):
"""Overrides Hypermodel's build method"""
# Hyperparameters to tune
CONV_filters = hp.Int(
"units_conv", min_value=32, max_value=256, step=32, default=256
......@@ -169,9 +173,12 @@ class SEQ_2_SEQ_AE(HyperModel):
class SEQ_2_SEQ_GMVAE(HyperModel):
"""Hyperparameter tuning pipeline for deepof.models.SEQ_2_SEQ_GMVAE"""
def __init__(
self,
input_shape,
batch_size,
CONV_filters=256,
LSTM_units_1=256,
LSTM_units_2=128,
......@@ -184,7 +191,9 @@ class SEQ_2_SEQ_GMVAE(HyperModel):
number_of_components=1,
predictor=True,
):
super().__init__()
self.input_shape = input_shape
self.batch_size = batch_size
self.CONV_filters = CONV_filters
self.LSTM_units_1 = LSTM_units_1
self.LSTM_units_2 = LSTM_units_2
......@@ -203,6 +212,8 @@ class SEQ_2_SEQ_GMVAE(HyperModel):
), "loss must be one of ELBO, MMD or ELBO+MMD (default)"
def build(self, hp):
"""Overrides Hypermodel's build method"""
# Hyperparameters to tune
DROPOUT_RATE = hp.Float(
"dropout_rate", min_value=0.0, max_value=0.5, default=0.25, step=0.05
......@@ -358,7 +369,9 @@ class SEQ_2_SEQ_GMVAE(HyperModel):
)
)
z = MMDiscrepancyLayer(prior=self.prior, beta=mmd_beta)(z)
z = MMDiscrepancyLayer(
batch_size=self.batch_size, prior=self.prior, beta=mmd_beta
)(z)
# Define and instantiate generator
generator = Model_D1(z)
......
......@@ -498,7 +498,7 @@ class coordinates:
raise ValueError(
"Distances not computed. Read the documentation for more details"
) #pragma: no cover
) # pragma: no cover
def get_angles(
self, degrees: bool = False, speed: int = 0, length: str = None
......@@ -536,12 +536,14 @@ class coordinates:
return table_dict(tabs, typ="angles")
raise ValueError("Angles not computed. Read the documentation for more details") #pragma: no cover
raise ValueError(
"Angles not computed. Read the documentation for more details"
) # pragma: no cover
def get_videos(self, play: bool = False):
"""Retuens the videos associated with the dataset as a list."""
if play: #pragma: no cover
if play: # pragma: no cover
raise NotImplementedError
return self._videos
......@@ -555,7 +557,7 @@ class coordinates:
def get_quality(self, report: bool = False):
"""Retrieves a dictionary with the tagging quality per video, as reported by DLC"""
if report: #pragma: no cover
if report: # pragma: no cover
profile = ProfileReport(
self._quality[report],
title="Quality Report, {}".format(report),
......@@ -619,9 +621,9 @@ class table_dict(dict):
raise NotImplementedError(
"Heatmaps only available for cartesian coordinates. "
"Set polar to False in get_coordinates and try again"
) #pragma: no cover
) # pragma: no cover
if not self._center: #pragma: no cover
if not self._center: # pragma: no cover
warnings.warn("Heatmaps look better if you center the data")
if self._arena == "circular":
......@@ -721,7 +723,7 @@ class table_dict(dict):
else:
raise ValueError(
"Invalid scaler. Select one of standard, minmax or None"
) #pragma: no cover
) # pragma: no cover
X_train = scaler.fit_transform(
X_train.reshape(-1, X_train.shape[-1])
......
......@@ -3,7 +3,6 @@ matplotlib~=3.1.3
networkx~=2.4
numpy~=1.18.1
pandas~=1.0.3
pandas-profiling~=2.5.0
regex~=2020.2.18
scipy~=1.5.2
seaborn~=0.10.0
......@@ -11,10 +10,10 @@ joblib~=0.16.0
sklearn~=0.0
scikit-learn~=0.23.2
tqdm~=4.42.0
tensorflow~=2.2.0
tensorflow-probability~=0.10.0
tensorflow~=2.0.0
hypothesis~=5.29.0
dash~=1.11.0
plotly~=4.5.0
setuptools~=49.6.0
pytest~=5.3.5
\ No newline at end of file
pytest~=5.3.5
keras-tuner~=1.0.1
\ No newline at end of file
......@@ -447,7 +447,7 @@ def recognize_arena(
while cap.isOpened() and fnum < recoglimit:
ret, frame = cap.read()
# if frame is read correctly ret is True
if not ret: #pragma: no cover
if not ret: # pragma: no cover
print("Can't receive frame (stream end?). Exiting ...")
break
......@@ -762,7 +762,7 @@ def single_behaviour_analysis(
if ylim is not None:
ax.set_ylim(ylim)
if save is not None: #pragma: no cover
if save is not None: # pragma: no cover
plt.savefig(save)
return_list.append(fig)
......@@ -1135,7 +1135,7 @@ def rule_based_tagging(
ret, frame = cap.read()
# if frame is read correctly ret is True
if not ret: #pragma: no cover
if not ret: # pragma: no cover
print("Can't receive frame (stream end?). Exiting ...")
break
......@@ -1281,7 +1281,7 @@ def rule_based_tagging(
2,
)
if show: #pragma: no cover
if show: # pragma: no cover
cv2.imshow("frame", frame)
if cv2.waitKey(1) == ord("q"):
......
# @author lucasmiranda42
# encoding: utf-8
# module deepof
"""
Testing module for deepof.hypermodels. Checks that all hyperparameter
tuning models are building properly in all possible configurations
"""
from hypothesis import given
from hypothesis import settings
from hypothesis import strategies as st
from kerastuner import HyperParameters
import deepof.hypermodels
import tensorflow as tf
tf.config.experimental_run_functions_eagerly(True)
@settings(deadline=None)
@given(
input_shape=st.tuples(
st.integers(min_value=100, max_value=1000),
st.integers(min_value=5, max_value=15),
st.integers(min_value=5, max_value=15),
)
)
def test_SEQ_2_SEQ_AE_hypermodel_build(input_shape):
deepof.hypermodels.SEQ_2_SEQ_AE(input_shape=input_shape).build(hp=HyperParameters())
@settings(deadline=None)
@given(
loss=st.one_of(st.just("ELBO"), st.just("MMD"), st.just("ELBO+MMD")),
kl_warmup_epochs=st.integers(min_value=0, max_value=5),
mmd_warmup_epochs=st.integers(min_value=0, max_value=5),
number_of_components=st.integers(min_value=1, max_value=5),
predictor=st.booleans(),
overlap_loss=st.booleans(),
entropy_reg_weight=st.one_of(st.just(0.0), st.just(1.0)),
)
def test_SEQ_2_SEQ_GMVAE_hypermodel_build(
loss,
kl_warmup_epochs,
mmd_warmup_epochs,
number_of_components,
predictor,
overlap_loss,
entropy_reg_weight,
):
deepof.hypermodels.SEQ_2_SEQ_GMVAE(
input_shape=(100, 15, 10,),
batch_size=10,
loss=loss,
kl_warmup_epochs=kl_warmup_epochs,
mmd_warmup_epochs=mmd_warmup_epochs,
number_of_components=number_of_components,
predictor=predictor,
).build(hp=HyperParameters())
# @author lucasmiranda42
# encoding: utf-8
# module deepof
"""
Testing module for deepof.hypermodels
"""
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment