예제 #1
0
def load_trained_model(
    experiment_key: str = "055b697548e048b78202cfebb78d6d8c",  # or simply use "latest"
    model_weights_path: str = "model/weights/srgan_generator_model_weights.npz",
):
    """
    Returns a trained Generator DeepBedMap neural network model.

    The model's weights and hyperparameters settings are retrieved from
    https://comet.ml/weiji14/deepbedmap using an `experiment_key` setting
    which can be set to 'latest' or some 32-character alphanumeric string.
    """
    srgan_train = _load_ipynb_modules("srgan_train.ipynb")

    # Download either 'latest' model weights from Comet.ML or one using experiment_key
    # Will also get the hyperparameters "num_residual_blocks" and "residual_scaling"
    num_residual_blocks, residual_scaling = _download_model_weights_from_comet(
        experiment_key=experiment_key, download_path=model_weights_path
    )

    # Architect the model with appropriate "num_residual_blocks" and "residual_scaling"
    model = srgan_train.GeneratorModel(
        num_residual_blocks=num_residual_blocks, residual_scaling=residual_scaling
    )

    # Load trained neural network weights into model
    chainer.serializers.load_npz(file=model_weights_path, obj=model)

    return model
예제 #2
0
def load_trained_model(
    experiment_key:
    str = "77126218f3504a06adbc7dfe3851bb28",  # or simply use "latest"
    model_weights_path: str = "model/weights/srgan_generator_model_weights.npz",
):
    """
    Returns a trained Generator DeepBedMap neural network model,
    and the hyperparameters that were used to train it.

    The model's weights and hyperparameters settings are retrieved from
    https://comet.ml/weiji14/deepbedmap using an `experiment_key` setting
    which can be set to 'latest' or some 32-character alphanumeric string.
    """
    srgan_train = _load_ipynb_modules("srgan_train.ipynb")

    # Download either 'latest' model weights from Comet.ML or one using experiment_key
    # Will also get the hyperparameters "num_residual_blocks" and "residual_scaling"
    hyperparameters = _download_model_weights_from_comet(
        experiment_key=experiment_key, download_path=model_weights_path)

    # Architect the model with appropriate "num_residual_blocks" and "residual_scaling"
    model = srgan_train.GeneratorModel(
        num_residual_blocks=int(hyperparameters["num_residual_blocks"]),
        residual_scaling=float(hyperparameters["residual_scaling"]),
    )

    # Load trained neural network weights into model
    chainer.serializers.load_npz(file=model_weights_path, obj=model)

    return model, hyperparameters
예제 #3
0
def _unit_test_ipynb(path: str):
    """
    Unit tests on loaded modules from a .ipynb file.
    Uses doctest.
    """
    assert path.endswith(".ipynb")

    module = _load_ipynb_modules(ipynb_path=path)
    num_failures, num_attempted = doctest.testmod(m=module, verbose=True)
    if num_failures > 0:
        sys.exit(num_failures)
예제 #4
0
def get_deepbedmap_model_inputs(
    window_bound: rasterio.coords.BoundingBox,
    padding: int = 1000,
    use_whole_rema: bool = False,
) -> (np.ndarray, np.ndarray, np.ndarray, np.ndarray):
    """
    Outputs one large tile for each of:
    BEDMAP2, REMA, MEASURES Ice Flow Velocity and Antarctic Snow Accumulation
    according to a given window_bound in the form of (xmin, ymin, xmax, ymax).
    """
    data_prep = _load_ipynb_modules("data_prep.ipynb")

    if window_bound == rasterio.coords.BoundingBox(
        left=-1_594_000.0, bottom=-166_500.0, right=-1_575_000.0, top=-95_500.0
    ):
        # Quickly pull from cached quilt storage if using (hardcoded) test region
        quilt.install(package="weiji14/deepbedmap/model/test", force=True)
        pkg = quilt.load(pkginfo="weiji14/deepbedmap/model/test")
        X_tile = pkg.X_tile()
        W1_tile = pkg.W1_tile()
        W2_tile = pkg.W2_tile()
        W3_tile = pkg.W3_tile()
예제 #5
0
    # to_skip,
    to_end,
    to_generate,
)
from paper.figures.PlotNeuralNet.pycore.tikzeng3 import (
    to_scalefont,
    to_flatimage,
    to_curvedskip,
    to_InOut,
    to_RRDB,
    to_ConvRelu,
    to_Upsample,
)
from features.environment import _load_ipynb_modules

data_prep = _load_ipynb_modules("data_prep.ipynb")
deepbedmap = _load_ipynb_modules("deepbedmap.ipynb")

# %% [markdown]
# # **Methodology**
#
# Uses personal [fork](https://github.com/weiji14/PlotNeuralNet)
# of [PlotNeuralNet](https://github.com/HarisIqbal88/PlotNeuralNet)
# for drawing convolutional neural network architecture diagram.

# %% [markdown]
# ### **Figure 1: DeepBedMap Model Architecture**

# %% [markdown]
# ### Thumbnail figures
예제 #6
0
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
import numpy as np
import pandas as pd
import pygmt as gmt
import quilt
import rasterio
import skimage

import comet_ml
import chainer
import cupy

from features.environment import _load_ipynb_modules, _download_model_weights_from_comet

data_prep = _load_ipynb_modules("data_prep.ipynb")

# %% [markdown]
# # 1. Gather datasets

# %% [markdown]
# ## 1.1 Get bounding box of our area of interest
#
# Basically predict on an place where we have groundtruth data to validate against.

# %%
def get_image_with_bounds(filepaths: list, indexers: dict = None) -> xr.DataArray:
    """
    Retrieve raster image in xarray.DataArray format patched
    with projected coordinate bounds as (xmin, ymin, xmax, ymax)