Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix CI failure #790

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ python -m pip install -e .[test]
```

This installs the Python bindings in [editable mode], which directly adds the files in the development directory are added to Python's import path.
Note that you must have the preferred version of GHC (see above) active in order to run this command otherwise you'll get a `Error: cabal: Could not resolve dependencies` error message.

When the Python bindings are installed in editable mode, you can run pytest directly:

Expand Down
38 changes: 20 additions & 18 deletions vehicle-python/tests/test_lossdl2_exec_tf_bounded.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def optimiser_for_x(

X_train = np.array([[0.0], [0.2], [0.4], [0.6], [0.8]])
X_test = np.array([[0.1], [0.3], [0.5], [0.7], [0.9]])
y_train = np.array([0, 0, 0, 1, 1])
y_test = np.array([0, 0, 1, 1, 1])
y_train = np.array([[0], [0], [0], [1], [1]])
y_test = np.array([[0], [0], [1], [1], [1]])

train_dataset = tf.data.Dataset.from_tensor_slices((X_train, y_train))
test_dataset = tf.data.Dataset.from_tensor_slices((X_test, y_test))
Expand All @@ -57,13 +57,11 @@ def optimiser_for_x(
# Train the network
num_epochs = 4

optimizer = tf.keras.optimizers.legacy.Adam()
optimizer = tf.keras.optimizers.Adam()
ce_batch_loss = tf.keras.losses.BinaryCrossentropy()

train_acc_metric = tf.keras.metrics.BinaryCrossentropy()
test_acc_metric = tf.keras.metrics.BinaryCrossentropy()
train_loss_metric = tf.keras.metrics.BinaryCrossentropy()
test_loss_metric = tf.keras.metrics.BinaryCrossentropy()

ce_loss_weight = 0
bounded_weight = 1
Expand Down Expand Up @@ -94,24 +92,28 @@ def optimiser_for_x(
train_acc_metric.update_state(y_batch_train, train_outputs)
train_loss_metric.update_state(y_batch_train, train_outputs)

# Run a testing loop at the end of each epoch.
for x_batch_test, y_batch_test in test_dataset:
test_outputs = model(x_batch_test, training=False)
test_acc_metric.update_state(y_batch_test, test_outputs)
test_loss_metric.update_state(y_batch_test, test_outputs)

train_acc = train_acc_metric.result()
test_acc = test_acc_metric.result()
train_loss = train_loss_metric.result()
test_loss = test_loss_metric.result()

train_acc_metric.reset_states()
test_acc_metric.reset_states()
train_loss_metric.reset_states()
test_loss_metric.reset_states()
train_acc_metric.reset_state()
train_loss_metric.reset_state()

print(f"Train acc: {float(train_acc):.4f}")
print(f"Train loss: {float(train_loss):.4f}")

test_acc_metric = tf.keras.metrics.BinaryCrossentropy()
test_loss_metric = tf.keras.metrics.BinaryCrossentropy()

test_loss = test_loss_metric.result()
test_acc = test_acc_metric.result()

# Run a testing loop at the end of each epoch.
for x_batch_test, y_batch_test in test_dataset:
test_outputs = model(x_batch_test, training=False)
test_acc_metric.update_state(y_batch_test, test_outputs)
test_loss_metric.update_state(y_batch_test, test_outputs)

test_acc_metric.reset_state()
test_loss_metric.reset_state()
print(f"Test acc: {float(test_acc):.4f}")
print(f"Test loss: {float(test_loss):.4f}")

Expand Down
Loading