Commit 3379ec5e 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 b7b7beec
stages:
- test
include:
- template: Code-Quality.gitlab-ci.yml
test:
stage: test
image: continuumio/anaconda3
......
......@@ -188,7 +188,7 @@ class uncorrelated_features_constraint(Constraint):
self.encoding_dim = encoding_dim
self.weightage = weightage
def get_config(self):
def get_config(self): # pragma: no cover
"""Updates Constraint metadata"""
config = super().get_config().copy()
......@@ -215,7 +215,7 @@ class uncorrelated_features_constraint(Constraint):
def uncorrelated_feature(self, x):
"""Adds a penalty on feature correlation, forcing more independent sets of weights"""
if self.encoding_dim <= 1:
if self.encoding_dim <= 1: # pragma: no cover
return 0.0
else:
output = K.sum(
......@@ -252,7 +252,7 @@ class DenseTranspose(Layer):
self.activation = tf.keras.activations.get(activation)
super().__init__(**kwargs)
def get_config(self):
def get_config(self): # pragma: no cover
"""Updates Constraint metadata"""
config = super().get_config().copy()
......@@ -280,7 +280,7 @@ class DenseTranspose(Layer):
z = tf.matmul(inputs, self.dense.weights[0], transpose_b=True)
return self.activation(z + self.biases)
def compute_output_shape(self, input_shape):
def compute_output_shape(self, input_shape): # pragma: no cover
"""Outputs the transposed shape"""
return input_shape[0], self.output_dim
......@@ -296,7 +296,7 @@ class KLDivergenceLayer(tfpl.KLDivergenceAddLoss):
self.is_placeholder = True
super(KLDivergenceLayer, self).__init__(*args, **kwargs)
def get_config(self):
def get_config(self): # pragma: no cover
"""Updates Constraint metadata"""
config = super().get_config().copy()
......@@ -330,7 +330,7 @@ class MMDiscrepancyLayer(Layer):
self.prior = prior
super(MMDiscrepancyLayer, self).__init__(*args, **kwargs)
def get_config(self):
def get_config(self): # pragma: no cover
"""Updates Constraint metadata"""
config = super().get_config().copy()
......@@ -364,7 +364,7 @@ class Gaussian_mixture_overlap(Layer):
self.samples = samples
super(Gaussian_mixture_overlap, self).__init__(*args, **kwargs)
def get_config(self):
def get_config(self): # pragma: no cover
"""Updates Constraint metadata"""
config = super().get_config().copy()
......@@ -440,7 +440,7 @@ class Entropy_regulariser(Layer):
self.axis = axis
super(Entropy_regulariser, self).__init__(*args, **kwargs)
def get_config(self):
def get_config(self): # pragma: no cover
"""Updates Constraint metadata"""
config = super().get_config().copy()
......
......@@ -38,8 +38,8 @@ class SEQ_2_SEQ_AE:
dropout_rate: float = 0.25,
encoding: int = 16,
learning_rate: float = 1e-5,
huber_delta: float = 100.0,
):
self.input_shape = input_shape
self.CONV_filters = units_conv
self.LSTM_units_1 = units_lstm
......@@ -49,6 +49,7 @@ class SEQ_2_SEQ_AE:
self.DROPOUT_RATE = dropout_rate
self.ENCODING = encoding
self.learn_rate = learning_rate
self.delta = huber_delta
def build(self) -> Tuple[Any, Any, Any]:
# Encoder Layers
......@@ -155,7 +156,7 @@ class SEQ_2_SEQ_AE:
model = Sequential([encoder, decoder], name="SEQ_2_SEQ_AE")
model.compile(
loss=Huber(reduction="sum", delta=100.0),
loss=Huber(reduction="sum", delta=self.delta),
optimizer=Nadam(lr=self.learn_rate, clipvalue=0.5,),
metrics=["mae"],
)
......@@ -183,6 +184,7 @@ class SEQ_2_SEQ_GMVAE:
overlap_loss=False,
entropy_reg_weight=0.0,
initialiser_iters=int(1e5),
huber_delta: float = 100.0,
):
self.input_shape = input_shape
self.batch_size = batch_size
......@@ -203,6 +205,7 @@ class SEQ_2_SEQ_GMVAE:
self.overlap_loss = overlap_loss
self.entropy_reg_weight = entropy_reg_weight
self.initialiser_iters = initialiser_iters
self.delta = huber_delta
if self.prior == "standard_normal":
init_means = far_away_uniform_initialiser(
......@@ -454,6 +457,7 @@ class SEQ_2_SEQ_GMVAE:
# end-to-end autoencoder
encoder = Model(x, z, name="SEQ_2_SEQ_VEncoder")
grouper = Model(x, z_cat, name="Deep_Gaussian_Mixture_clustering")
# noinspection PyUnboundLocalVariable
gmvaep = Model(
inputs=x,
outputs=(
......@@ -478,8 +482,10 @@ class SEQ_2_SEQ_GMVAE:
_x_decoded_mean = TimeDistributed(Dense(self.input_shape[2]))(_generator)
generator = Model(g, _x_decoded_mean, name="SEQ_2_SEQ_VGenerator")
def huber_loss(x_, x_decoded_mean_):
huber = Huber(reduction="sum", delta=100.0)
def huber_loss(x_, x_decoded_mean_): # pragma: no cover
"""Computes huber loss with a fixed delta"""
huber = Huber(reduction="sum", delta=self.delta)
return self.input_shape[1:] * huber(x_, x_decoded_mean_)
gmvaep.compile(
......
......@@ -498,7 +498,7 @@ class coordinates:
raise ValueError(
"Distances not computed. Read the documentation for more details"
)
) #pragma: no cover
def get_angles(
self, degrees: bool = False, speed: int = 0, length: str = None
......@@ -536,12 +536,12 @@ class coordinates:
return table_dict(tabs, typ="angles")
raise ValueError("Angles not computed. Read the documentation for more details")
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:
if play: #pragma: no cover
raise NotImplementedError
return self._videos
......@@ -555,7 +555,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:
if report: #pragma: no cover
profile = ProfileReport(
self._quality[report],
title="Quality Report, {}".format(report),
......@@ -570,9 +570,9 @@ class coordinates:
return self._arena, self._arena_dims, self._scales
def rule_based_annotation(self):
"""Annotates coordinates using a simple rule-based pipeline"""
pass
# def rule_based_annotation(self):
# """Annotates coordinates using a simple rule-based pipeline"""
# pass
class table_dict(dict):
......@@ -619,9 +619,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
if not self._center:
if not self._center: #pragma: no cover
warnings.warn("Heatmaps look better if you center the data")
if self._arena == "circular":
......@@ -721,7 +721,7 @@ class table_dict(dict):
else:
raise ValueError(
"Invalid scaler. Select one of standard, minmax or None"
)
) #pragma: no cover
X_train = scaler.fit_transform(
X_train.reshape(-1, X_train.shape[-1])
......
......@@ -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:
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:
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:
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:
if show: #pragma: no cover
cv2.imshow("frame", frame)
if cv2.waitKey(1) == ord("q"):
......
......@@ -57,7 +57,7 @@ def plot_heatmap(
[x.set_ylim(ylim) for x in ax]
[x.set_title(bp) for x, bp in zip(ax, bodyparts)]
if save:
if save: # pragma: no cover
plt.savefig(save)
return heatmaps
......@@ -133,7 +133,7 @@ def model_comparison_plot(
spl2.set_xlabel("Number of components")
spl2.set_ylabel("BIC value")
if save:
if save: # pragma: no cover
plt.savefig(save)
return modelcomp
......@@ -38,8 +38,7 @@ def test_SEQ_2_SEQ_AE_build(input_shape):
number_of_components=st.integers(min_value=1, max_value=5),
predictor=st.booleans(),
overlap_loss=st.booleans(),
entropy_reg_weight=st.floats(min_value=0.0, max_value=1.0),
init_iters=st.just(10),
entropy_reg_weight=st.one_of(st.just(0.0), st.just(1.0)),
)
def test_SEQ_2_SEQ_GMVAE_build(
loss,
......@@ -49,7 +48,6 @@ def test_SEQ_2_SEQ_GMVAE_build(
predictor,
overlap_loss,
entropy_reg_weight,
init_iters,
):
deepof.models.SEQ_2_SEQ_GMVAE(
input_shape=(100, 15, 10,),
......@@ -60,5 +58,5 @@ def test_SEQ_2_SEQ_GMVAE_build(
predictor=predictor,
overlap_loss=overlap_loss,
entropy_reg_weight=entropy_reg_weight,
initialiser_iters=init_iters,
initialiser_iters=1,
).build()
Markdown is supported
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