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

Train sampling #134

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
188 changes: 94 additions & 94 deletions usl_models/notebooks/train_flood_model.ipynb
Original file line number Diff line number Diff line change
@@ -1,95 +1,95 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Flood Model Training Notebook\n",
"\n",
"Train a Flood ConvLSTM Model using `usl_models` lib."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
"import tensorflow as tf\n",
"from usl_models.flood_ml import constants\n",
"from usl_models.flood_ml.model import FloodModel, FloodModelParams\n",
"from usl_models.flood_ml.dataset import load_dataset_windowed, load_dataset\n",
"\n",
"sim_names=[\"Manhattan-config_v1/Rainfall_Data_1.txt\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dataset = load_dataset_windowed(sim_names=sim_names, batch_size=4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model = FloodModel(FloodModelParams())\n",
"dataset = load_dataset_windowed(sim_names=sim_names, batch_size=4)\n",
"model.fit(dataset, epochs=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Test calling the model on some data.\n",
"inputs, labels_ = next(iter(dataset))\n",
"prediction = model.call(inputs)\n",
"prediction.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Test calling the model for n predictions\n",
"full_dataset = load_dataset(sim_names=sim_names, batch_size=1)\n",
"inputs, labels_ = next(iter(full_dataset))\n",
"predictions = model.call_n(inputs, n=4)\n",
"predictions.shape"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Flood Model Training Notebook\n",
"\n",
"Train a Flood ConvLSTM Model using `usl_models` lib."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
"import tensorflow as tf\n",
"from usl_models.flood_ml import constants\n",
"from usl_models.flood_ml.model import FloodModel, FloodModelParams\n",
"from usl_models.flood_ml.dataset import load_dataset_windowed, load_dataset\n",
"\n",
"sim_names=[\"Manhattan-config_v1/Rainfall_Data_1.txt\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dataset = load_dataset_windowed(sim_names=sim_names, batch_size=4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model = FloodModel(FloodModelParams())\n",
"dataset = load_dataset_windowed(sim_names=sim_names, batch_size=4)\n",
"model.fit(dataset, epochs=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Test calling the model on some data.\n",
"inputs, labels_ = next(iter(dataset))\n",
"prediction = model.call(inputs)\n",
"prediction.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Test calling the model for n predictions\n",
"full_dataset = load_dataset(sim_names=sim_names, batch_size=1)\n",
"inputs, labels_ = next(iter(full_dataset))\n",
"predictions = model.call_n(inputs, n=4)\n",
"predictions.shape"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
22 changes: 20 additions & 2 deletions usl_models/tests/flood_ml/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def test_load_dataset_full(mock_metastore) -> None:

# Set some URLs to return from our metastore functions.
mock_metastore.get_temporal_feature_metadata.return_value = {
"as_vector_gcs_uri": "gs://temporal-features/temporal-feature.npy"
"as_vector_gcs_uri": "gs://temporal-features/temporal-feature.npy",
"rainfall_duration": 4,
}
mock_metastore.get_spatial_feature_and_label_chunk_metadata.return_value = [
(
Expand Down Expand Up @@ -73,8 +74,16 @@ def mock_blob_func(blob_name):
[
mock.call.bucket("temporal-features"),
mock.call.bucket().blob("temporal-feature.npy"),
]
)
mock_storage_client.assert_has_calls(
[
mock.call.bucket("spatial-features"),
mock.call.bucket().blob("spatial-feature.npy"),
]
)
mock_storage_client.assert_has_calls(
[
mock.call.bucket("labels"),
mock.call.bucket().blob("labels.npy"),
]
Expand Down Expand Up @@ -131,7 +140,8 @@ def test_load_dataset_windowed(mock_metastore) -> None:

# Set some URLs to return from our metastore functions.
mock_metastore.get_temporal_feature_metadata.return_value = {
"as_vector_gcs_uri": "gs://temporal-features/temporal-feature.npy"
"as_vector_gcs_uri": "gs://temporal-features/temporal-feature.npy",
"rainfall_duration": 4,
}
mock_metastore.get_spatial_feature_and_label_chunk_metadata.return_value = [
(
Expand Down Expand Up @@ -186,8 +196,16 @@ def mock_blob_func(blob_name):
[
mock.call.bucket("temporal-features"),
mock.call.bucket().blob("temporal-feature.npy"),
]
)
mock_storage_client.assert_has_calls(
[
mock.call.bucket("spatial-features"),
mock.call.bucket().blob("spatial-feature.npy"),
]
)
mock_storage_client.assert_has_calls(
[
mock.call.bucket("labels"),
mock.call.bucket().blob("labels.npy"),
]
Expand Down
Loading