Skip to content

Commit

Permalink
Fixed dimension mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewDaggitt committed Mar 28, 2024
1 parent e289a8b commit 0d42e07
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
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
36 changes: 19 additions & 17 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 @@ -61,9 +61,7 @@ def optimiser_for_x(
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

0 comments on commit 0d42e07

Please sign in to comment.