Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
test: improve keras tests (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxiao authored Aug 19, 2021
1 parent 0474b94 commit a912e0f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install wheel
pip install -r ./github/requirements-test.txt
pip install -r ./github/requirements-cicd.txt
pip install -r .github/requirements-test.txt
pip install -r .github/requirements-cicd.txt
pip install -r requirements.txt
pip install --no-cache-dir .
export JINA_LOG_LEVEL="ERROR"
Expand Down
15 changes: 15 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
codecov:
# https://docs.codecov.io/docs/comparing-commits
allow_coverage_offsets: true
coverage:
status:
project:
default:
informational: true
target: auto # auto compares coverage to the previous base commit
comment:
layout: "reach, diff, flags, files"
behavior: default
require_changes: false # if true: only post the comment if coverage changes
branches: # branch names that can post comment
- "main"
19 changes: 12 additions & 7 deletions tests/integration/test_keras_trainer.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# build a simple dense network with bottleneck as 10-dim
import numpy as np
import tensorflow as tf
from tensorflow import keras

# wrap the user model with our trainer
from trainer.keras import KerasTrainer

# generate artificial positive & negative data
from ..data_generator import fashion_match_doc_generator as fmdg


def test_simple_sequential_model():
def test_simple_sequential_model(tmpdir):
embed_dim = 10

user_model = tf.keras.Sequential(
[
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(
10, activity_regularizer=tf.keras.regularizers.l1(0.01)
embed_dim, activity_regularizer=tf.keras.regularizers.l1(0.01)
),
]
)
Expand All @@ -23,4 +23,9 @@ def test_simple_sequential_model():

# fit and save the checkpoint
kt.fit(fmdg(num_total=1000), epochs=10, batch_size=256)
kt.save('./examples/fashion/trained')
kt.save(tmpdir / 'trained.kt')

embedding_model = keras.models.load_model(tmpdir / 'trained.kt')
num_samples = 100
r = embedding_model.predict(np.random.random([100, 28, 28]))
assert r.shape == (num_samples, embed_dim)

0 comments on commit a912e0f

Please sign in to comment.