Skip to content

Instantly share code, notes, and snippets.

View ShihengDuan's full-sized avatar
☘️
Focusing

ShihengATM ShihengDuan

☘️
Focusing
View GitHub Profile
@bobhaffner
bobhaffner / pandas_io_performance.ipynb
Last active June 2, 2024 13:48
Pandas io performance
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ZijiaLewisLu
ZijiaLewisLu / Tricks to Speed Up Data Loading with PyTorch.md
Last active July 11, 2024 11:00
Tricks to Speed Up Data Loading with PyTorch

In most of deep learning projects, the training scripts always start with lines to load in data, which can easily take a handful minutes. Only after data ready can start testing my buggy code. It is so frustratingly often that I wait for ten minutes just to find I made a stupid typo, then I have to restart and wait for another ten minutes hoping no other typos are made.

In order to make my life easy, I devote lots of effort to reduce the overhead of I/O loading. Here I list some useful tricks I found and hope they also save you some time.

  1. use Numpy Memmap to load array and say goodbye to HDF5.

    I used to relay on HDF5 to read/write data, especially when loading only sub-part of all data. Yet that was before I realized how fast and charming Numpy Memmapfile is. In short, Memmapfile does not load in the whole array at open, and only later "lazily" load in the parts that are required for real operations.

Sometimes I may want to copy the full array to memory at once, as it makes later operations

@ShihengDuan
ShihengDuan / calculation_metrics.py
Last active September 14, 2023 03:32
Calculate KGE, NSE for 3-D xarray data (time, lat, Lon)
def calculate_kge(obs_data, model_data):
mean_obs = obs_data.mean(dim='time')
mean_model = model_data.mean(dim='time')
obs_std = obs_data.std(dim='time')
model_std = model_data.std(dim='time')
upper = (model_data-mean_model)*(obs_data-mean_obs)
upper = upper.sum(dim='time')
lower_x = np.square(model_data-mean_model)