-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update train.yaml and train.py, and add phasenet_plus.ipynb
- Loading branch information
Showing
8 changed files
with
533 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import obspy\n", | ||
"import torch\n", | ||
"import os\n", | ||
"from glob import glob" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Download event data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!wget -q https://github.com/AI4EPS/PhaseNet/releases/download/test_data/test_data.zip -O test_data.zip\n", | ||
"!unzip -q -o test_data.zip\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Run PhaseNet-Plus" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"mseed_list = glob('test_data/mseed/*.mseed')\n", | ||
"with open(\"mseed_list.txt\", \"w\") as f:\n", | ||
" f.write(\"\\n\".join(mseed_list))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ngpu = torch.cuda.device_count()\n", | ||
"base_cmd = \"../predict.py --model phasenet_plus --data_list mseed_list.txt --result_path ./results --format=mseed --batch_size 1 --workers 1\"\n", | ||
"\n", | ||
"plot_figure = True\n", | ||
"if plot_figure:\n", | ||
" base_cmd += \" --plot_figure\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"python ../predict.py --model phasenet_plus --data_list mseed_list.txt --result_path ./results --format=mseed --batch_size 1 --workers 1 --plot_figure --device cpu\n", | ||
"Not using distributed mode\n", | ||
"Namespace(model='phasenet_plus', resume='', backbone='unet', phases=['P', 'S'], device='cpu', workers=1, batch_size=1, use_deterministic_algorithms=False, amp=False, world_size=1, dist_url='env://', data_path='./', data_list='mseed_list.txt', hdf5_file=None, prefix='', format='mseed', dataset='das', result_path='./results', plot_figure=True, min_prob=0.3, add_polarity=False, add_event=False, highpass_filter=0.0, response_xml=None, folder_depth=0, cut_patch=False, nt=20480, nx=5120, resample_time=False, resample_space=False, system=None, location=None, skip_existing=False, distributed=False)\n", | ||
"Total samples: ./.mseed : 16 files\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"Predicting: 0%| | 0/16 [00:00<?, ?it/s]" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"if ngpu == 0:\n", | ||
" cmd = f\"python {base_cmd} --device cpu\"\n", | ||
"elif ngpu == 1:\n", | ||
" cmd = f\"python {base_cmd}\"\n", | ||
"else:\n", | ||
" cmd = f\"torchrun --nproc_per_node {ngpu} {base_cmd}\"\n", | ||
"\n", | ||
"print(cmd)\n", | ||
"os.system(cmd);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Plot results" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from PIL import Image\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"fig, axes = plt.subplots(4, 4, figsize=(12, 12))\n", | ||
"axes = axes.flatten()\n", | ||
"\n", | ||
"for i, f in enumerate(glob('results/figures_phasenet_plus/*.png')):\n", | ||
" img = Image.open(f) \n", | ||
" axes[i].imshow(img)\n", | ||
" axes[i].axis('off')\n", | ||
" if i >= 15:\n", | ||
" break\n", | ||
"plt.tight_layout()\n", | ||
"plt.show()" | ||
] | ||
} | ||
], | ||
"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.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.