Overview of HKO-7 Benchmark Statistics
masterhko_data/benchmark_stat directory is used to store the necessary statistics required for running the benchmark environment within the precipitation-nowcasting project.repository·master·Indexed 20 days ago
https://github.com/hzzone/precipitation-nowcastingA PyTorch implementation of encoder-forecaster models, including TrajGRU and ConvLSTM, designed for precipitation nowcasting and benchmarked on the HKO-7 dataset. The repository includes tools for training with balanced MSE/MAE or WeightedCrossEntropyLoss, a VarFlow Python wrapper with a C++ core, and utilities for downloading and managing the HKO-7 dataset.
hko_data/benchmark_stat directory is used to store the necessary statistics required for running the benchmark environment within the precipitation-nowcasting project.This repository provides PyTorch-based encoder-forecaster models for precipitation nowcasting using Recurrent Neural Networks (RNNs). The primary implementations include:
All models expect input data in the shape S*B*C*H*W (Sequence, Batch, Channel, Height, Width) and have been validated on the HKO-7 dataset.
The VarFlow distribution includes the following files for implementation and testing:
VarFlow.cpp: The implementation of the VarFlow class.VarFlow.h: The header definition of the VarFlow class.example.cpp: A complete usage example demonstrating how to instantiate and use the class.Data\yos_img_08.jpg & Data\yos_img_09.jpg: Sample images from the Yosemite flyby sequence for testing the algorithm.hko7_rainy_train_days.txt: Frame names for the training set.hko7_rainy_valid_days.txt: Frame names for the validation set.hko7_rainy_test_days.txt: Frame names for the testing set.intensity_day.pkl: The daily intensity of the HKO-7 data.pd directory)These files contain datetime information and should be loaded using pandas.read_pickle():
hko7_all.pkl: Datetimes from 2009 to 2015.hko7_all_09_14.pkl: Datetimes from 2009 to 2014.hko7_all_15.pkl: Datetimes in the year 2015.hko7_rainy_train.pkl: Datetimes for the training set.hko7_rainy_valid.pkl: Datetimes for the validation set.hko7_rainy_test.pkl: Datetimes for the test set.The VarFlow class implements the variational optical flow algorithm described by Bruhn et al. To use it, include VarFlow.h in your C++ project and link against the OpenCV libraries.
Note: The class was originally developed with OpenCV 1.1, but it is compatible with OpenCV 2.0. Ensure your compiler environment is correctly configured to link with your specific OpenCV version.
// See example.cpp for a complete usage implementation
#include "VarFlow.h"The VarFlow Python wrapper requires a two-step installation process: first, compiling the underlying C++ core using cmake, and second, installing the Python package using setup.py.
Create a build directory and run cmake. Depending on your operating system, use the appropriate commands below.
Use the Visual Studio generator:
mkdir build
cmake -G "Visual Studio 14 2015 Win64" ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_CONFIGURATION_TYPES="Release" ^
..mkdir build
cd build
cmake ..If cmake fails to find OpenCV, manually specify the path using the -DOpenCV_DIR flag:
mkdir build
cd build
cmake -DOpenCV_DIR=/usr/local/software/opencv/share/OpenCV ..
makeOnce the build is successful, validate the installation by running the example script located at varflow/varflow.py. If it runs without error, install the package in development mode:
python setup.py developmkdir build
cd build
cmake -DOpenCV_DIR=/usr/local/software/opencv/share/OpenCV ..
make
python setup.py developTraining follows a two-step process using the HKO-7 dataset:
config.py to point to your local dataset location.# Step 1: Initial training
python3 experiments/trajGRU_balanced_mse_mae/main.py
# Step 2: Fine-tuning
python3 experiments/trajGRU_frame_weighted_mse/main.pyTo obtain the HKO-7 dataset files, run the provided download script using Python. This will populate the necessary directories with the dataset files.
python download_all.pyTo run the models, ensure your system meets the following requirements:
Pretrained models are available for download via Dropbox to skip the training process.
https://www.dropbox.com/sh/i5goltdq83dmkvc/AABBe5wTuEQF5j3VSMszVQSaa?dl=0This entrypoint script configures and executes a training and testing loop for the TrajGRU model architecture using a balanced Weighted_mse_mae loss function. It integrates an Encoder and a Forecaster into an EF (Encoder-Forecaster) wrapper. The training process uses the Adam optimizer and a MultiStepLR learning rate scheduler.
import torch
from nowcasting.config import cfg
from nowcasting.models.forecaster import Forecaster
from nowcasting.models.encoder import Encoder
from nowcasting.models.model import EF
from nowcasting.models.loss import Weighted_mse_mae
from nowcasting.models.trajGRU import TrajGRU
from nowcasting.train_and_test import train_and_test
from experiments.net_params import encoder_params, forecaster_params
# Configuration
batch_size = cfg.GLOBAL.BATCH_SZIE
max_iterations = 100000
test_iteration_interval = 1000
test_and_save_checkpoint_iterations = 1000
LR = 1e-4
# Model Setup
criterion = Weighted_mse_mae().to(cfg.GLOBAL.DEVICE)
encoder = Encoder(encoder_params[0], encoder_params[1]).to(cfg.GLOBAL.DEVICE)
forecaster = Forecaster(forecaster_params[0], forecaster_params[1]).to(cfg.GLOBAL.DEVICE)
encoder_forecaster = EF(encoder, forecaster).to(cfg.GLOBAL.DEVICE)
# Optimization
optimizer = torch.optim.Adam(encoder_forecaster.parameters(), lr=LR)
mult_step_scheduler = torch.optim.lr_scheduler.MultiStepLR(optimizer, milestones=[30000, 60000], gamma=0.1)
# Execution
train_and_test(
encoder_forecaster,
optimizer,
criterion,
mult_step_scheduler,
batch_size,
max_iterations,
test_iteration_interval,
test_and_save_checkpoint_iterations,
folder_name
)To execute a Conv2D-based precipitation nowcasting training experiment, use the train_and_test function. This function orchestrates the training loop, evaluation, and checkpoint saving. It requires a model, an optimizer, a loss criterion, a learning rate scheduler, and several hyperparameter/interval settings.
Key parameters for train_and_test:
model: The neural network instance (e.g., a Predictor configured with conv2d_params).optimizer: The optimization algorithm (e.g., torch.optim.Adam).criterion: The loss function (e.g., Weighted_mse_mae).exp_lr_scheduler: The learning rate scheduler (e.g., torch.optim.lr_scheduler.StepLR).batch_size: Number of samples per training batch.max_iterations: Total number of training iterations.test_iteration_interval: Frequency of evaluation iterations.test_and_save_checkpoint_iterations: Frequency of evaluation and checkpoint saving.folder_name: The directory name used for organizing experiment outputs.from nowcasting.train_and_test import train_and_test
# Example setup
train_and_test(
model,
optimizer,
criterion,
exp_lr_scheduler,
batch_size=4,
max_iterations=80000,
test_iteration_interval=10000,
test_and_save_checkpoint_iterations=10000,
folder_name='conv2d'
)