Aaaapril4 commited on
Commit
2178647
·
1 Parent(s): f13abb7

two version

Browse files
Files changed (3) hide show
  1. README.md +0 -54
  2. config.json +0 -22
  3. upload_to_hf.py +152 -33
README.md DELETED
@@ -1,54 +0,0 @@
1
- ---
2
- language: en
3
- tags:
4
- - seismic
5
- - earthquake
6
- - phase-picking
7
- - deep-learning
8
- - pytorch
9
- license: mit
10
- datasets:
11
- - PS_Alaska
12
- metrics:
13
- - f1-score
14
- - precision
15
- - recall
16
- ---
17
-
18
- # PhaseNet-TF: Advanced Seismic Arrival Time Detection
19
-
20
- ## Model Description
21
-
22
- PhaseNet-TF is an advanced deep learning model for automatic seismic phase picking (P-wave, S-wave, and PS-wave detection) using spectrogram-based image segmentation approaches. The model leverages DeepLabV3Plus architecture to detect seismic arrivals with high accuracy, especially for weak and noisy signals from ocean-bottom seismometers and weak phases such as slab interface refracted PS and SP waves. This Alaska version is specifically trained on the PS_Alaska dataset for P and S phases. For more details, please refer to the paper and the [PhaseNet-TF](https://github.com/swei-seismo/PhaseNet-TF) repository.
23
-
24
- ## Model Architecture
25
-
26
- - **Backbone**: DeepLabV3Plus with ResNet34 encoder
27
- - **Input**: 3-component seismic waveforms converted to 6-channel spectrograms (real + imaginary)
28
- - **Output**: Probability maps for P, S, PS phases and noise
29
- - **Sampling Rate**: 40 Hz (dt_s = 0.025s)
30
- - **Window Length**: 4800 points (120 seconds)
31
- - **Spectrogram Size**: 64 × 4800 (frequency × time)
32
- - **Input Channels**: 6 (3 real + 3 imaginary spectrogram channels)
33
- - **Output Classes**: 4 (noise, P, S, PS)
34
-
35
- ## Load the checkpoint
36
- checkpoint = torch.load("alaska_iter2.ckpt", map_location="cpu")
37
-
38
- ## Citation
39
-
40
- If you use this model in your research, please cite:
41
-
42
- ```bibtex
43
- @article{jie2025background,
44
- title={Background Seismicity and Aftershocks of the 2020-2021 Large Earthquakes at the Alaska Peninsula Revealed by a Deep-learning-based Catalog},
45
- author={Jie, Yaqi and Wei, Songqiao Shawn and Zhu, Weiqiang and Freymueller, Jeffrey Todd and Elliott, Julie},
46
- journal={Authorea Preprints},
47
- year={2025},
48
- publisher={Authorea}
49
- }
50
- ```
51
-
52
- ## License
53
-
54
- This model is licensed under the MIT License.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "model_type": "phasenet-tf",
3
- "architecture": "DeepLabV3Plus with ResNet34 encoder",
4
- "input_channels": 6,
5
- "output_classes": 4,
6
- "sampling_rate": 40,
7
- "window_length": 4800,
8
- "phases": [
9
- "P",
10
- "S",
11
- "PS"
12
- ],
13
- "framework": "pytorch",
14
- "license": "mit",
15
- "tags": [
16
- "seismic",
17
- "earthquake",
18
- "phase-picking",
19
- "deep-learning",
20
- "deeplabv3plus"
21
- ]
22
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
upload_to_hf.py CHANGED
@@ -10,8 +10,55 @@ from huggingface_hub import hf_hub_download
10
  import torch
11
  import yaml
12
 
13
- def create_model_card():
14
  """Create a comprehensive model card for PhaseNet-TF"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  return """---
16
  language: en
17
  tags:
@@ -29,11 +76,39 @@ metrics:
29
  - recall
30
  ---
31
 
32
- # PhaseNet-TF: Advanced Seismic Arrival Time Detection
33
 
34
  ## Model Description
35
 
36
- PhaseNet-TF is an advanced deep learning model for automatic seismic phase picking (P-wave, S-wave, and PS-wave detection) using spectrogram-based image segmentation approaches. The model leverages DeepLabV3Plus architecture to detect seismic arrivals with high accuracy, especially for weak and noisy signals from ocean-bottom seismometers and weak phases such as slab interface refracted PS and SP waves. This Alaska version is specifically trained on the PS_Alaska dataset for P and S phases. For more details, please refer to the paper and the [PhaseNet-TF](https://github.com/swei-seismo/PhaseNet-TF) repository.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  ## Model Architecture
39
 
@@ -46,9 +121,6 @@ PhaseNet-TF is an advanced deep learning model for automatic seismic phase picki
46
  - **Input Channels**: 6 (3 real + 3 imaginary spectrogram channels)
47
  - **Output Classes**: 4 (noise, P, S, PS)
48
 
49
- ## Load the checkpoint
50
- checkpoint = torch.load("alaska_iter2.ckpt", map_location="cpu")
51
-
52
  ## Citation
53
 
54
  If you use this model in your research, please cite:
@@ -68,28 +140,14 @@ If you use this model in your research, please cite:
68
  This model is licensed under the MIT License.
69
  """
70
 
71
- def create_config_json(model_path):
72
- """Create config.json with model metadata"""
73
- config = {
74
- "model_type": "phasenet-tf",
75
- "architecture": "DeepLabV3Plus with ResNet34 encoder",
76
- "input_channels": 6, # 3-component real + 3-component imaginary spectrograms
77
- "output_classes": 4, # noise, P, S, PS
78
- "sampling_rate": 40, # 1/0.025 = 40 Hz
79
- "window_length": 4800, # 120 seconds at 40 Hz
80
- "phases": ["P", "S", "PS"],
81
- "framework": "pytorch",
82
- "license": "mit",
83
- "tags": ["seismic", "earthquake", "phase-picking", "deep-learning", "deeplabv3plus"]
84
- }
85
- return config
86
-
87
  def upload_model_to_hf(
88
  checkpoint_path: str,
89
  config_path: str = None,
90
  repo_name: str = "PhaseNet-TF_Alaska",
91
  username: str = None,
92
- token: str = None
 
 
93
  ):
94
  """Upload model to Hugging Face Hub"""
95
 
@@ -121,56 +179,113 @@ def upload_model_to_hf(
121
  print(f"Error creating repository: {e}")
122
  return
123
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  # Upload checkpoint
125
- print("Uploading model checkpoint...")
126
  upload_file(
127
  path_or_fileobj=checkpoint_path,
128
- path_in_repo="pytorch_model.bin",
129
  repo_id=repo_id,
130
  token=token
131
  )
132
 
133
- # Upload config
134
  if config_path and os.path.exists(config_path):
135
- print("Uploading config file...")
 
136
  upload_file(
137
  path_or_fileobj=config_path,
138
- path_in_repo="config.yaml",
139
  repo_id=repo_id,
140
  token=token
141
  )
142
 
143
  # Create and upload config.json
144
- config_json = create_config_json(checkpoint_path)
145
  config_json_path = "config.json"
146
  with open(config_json_path, 'w') as f:
147
  json.dump(config_json, f, indent=2)
148
 
149
  upload_file(
150
  path_or_fileobj=config_json_path,
151
- path_in_repo="config.json",
152
  repo_id=repo_id,
153
  token=token
154
  )
155
 
156
  # Create and upload README.md
157
- model_card = create_model_card()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  readme_path = "README.md"
159
  with open(readme_path, 'w') as f:
160
  f.write(model_card)
161
 
162
  upload_file(
163
  path_or_fileobj=readme_path,
164
- path_in_repo="README.md",
165
  repo_id=repo_id,
166
  token=token
167
  )
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  # Clean up temporary files
170
  os.remove(config_json_path)
171
  os.remove(readme_path)
172
 
173
  print(f"Model uploaded successfully to https://huggingface.co/{repo_id}")
 
 
174
 
175
  if __name__ == "__main__":
176
  import argparse
@@ -181,6 +296,8 @@ if __name__ == "__main__":
181
  parser.add_argument("--repo-name", default="PhaseNet-TF_Alaska", help="Repository name")
182
  parser.add_argument("--username", help="Hugging Face username (optional if already logged in)")
183
  parser.add_argument("--token", help="Hugging Face token (optional if already logged in)")
 
 
184
 
185
  args = parser.parse_args()
186
 
@@ -189,5 +306,7 @@ if __name__ == "__main__":
189
  config_path=args.config,
190
  repo_name=args.repo_name,
191
  username=args.username,
192
- token=args.token
 
 
193
  )
 
10
  import torch
11
  import yaml
12
 
13
+ def create_model_card(version=None):
14
  """Create a comprehensive model card for PhaseNet-TF"""
15
+ title = f"# PhaseNet-TF Alaska"
16
+ if version:
17
+ title = f"# PhaseNet-TF Alaska - {version}"
18
+
19
+ return f"""{title}
20
+
21
+ ## Model Description
22
+
23
+ PhaseNet-TF is an advanced deep learning model for automatic seismic phase picking (P-wave, S-wave, and PS-wave detection) using spectrogram-based image segmentation approaches. The model leverages DeepLabV3Plus architecture to detect seismic arrivals with high accuracy, especially for weak and noisy signals from ocean-bottom seismometers and weak phases such as slab interface refracted PS and SP waves. This Alaska version is specifically trained on the PS_Alaska dataset for P and S phases. For more details, please refer to the paper and the [PhaseNet-TF](https://github.com/swei-seismo/PhaseNet-TF) repository.
24
+
25
+ ## Model Architecture
26
+
27
+ - **Backbone**: DeepLabV3Plus with ResNet34 encoder
28
+ - **Input**: 3-component seismic waveforms converted to 6-channel spectrograms (real + imaginary)
29
+ - **Output**: Probability maps for P, S, PS phases and noise
30
+ - **Sampling Rate**: 40 Hz (dt_s = 0.025s)
31
+ - **Window Length**: 4800 points (120 seconds)
32
+ - **Spectrogram Size**: 64 × 4800 (frequency × time)
33
+ - **Input Channels**: 6 (3 real + 3 imaginary spectrogram channels)
34
+ - **Output Classes**: 4 (noise, P, S, PS)
35
+
36
+ ## Load the checkpoint
37
+ """
38
+
39
+ def create_config_json(model_path, version=None):
40
+ """Create config.json with model metadata"""
41
+ config = {
42
+ "model_type": "phasenet-tf",
43
+ "architecture": "DeepLabV3Plus with ResNet34 encoder",
44
+ "input_channels": 6, # 3-component real + 3-component imaginary spectrograms
45
+ "output_classes": 4, # noise, P, S, PS
46
+ "sampling_rate": 40, # 1/0.025 = 40 Hz
47
+ "window_length": 4800, # 120 seconds at 40 Hz
48
+ "phases": ["P", "S", "PS"],
49
+ "framework": "pytorch",
50
+ "license": "mit",
51
+ "tags": ["seismic", "earthquake", "phase-picking", "deep-learning", "deeplabv3plus"]
52
+ }
53
+
54
+ if version:
55
+ config["version"] = version
56
+ config["checkpoint_file"] = f"pytorch_model_{version}.bin"
57
+
58
+ return config
59
+
60
+ def create_main_readme():
61
+ """Create a main README that showcases both versions"""
62
  return """---
63
  language: en
64
  tags:
 
76
  - recall
77
  ---
78
 
79
+ # PhaseNet-TF Alaska: Advanced Seismic Arrival Time Detection
80
 
81
  ## Model Description
82
 
83
+ PhaseNet-TF is an advanced deep learning model for automatic seismic phase picking (P-wave, S-wave, and PS-wave detection) using spectrogram-based image segmentation approaches. The model leverages DeepLabV3Plus architecture to detect seismic arrivals with high accuracy, especially for weak and noisy signals from ocean-bottom seismometers and weak phases such as slab interface refracted PS and SP waves. This Alaska version is specifically trained on the PS_Alaska dataset for P and S phases.
84
+
85
+ ## Available Versions
86
+
87
+ This repository contains two versions of the PhaseNet-TF Alaska model:
88
+
89
+ ### 🔄 Iteration 1
90
+ - **Model File**: `pytorch_model_iter1.bin`
91
+ - **Config**: `config_iter1.json`
92
+ - **Documentation**: [README_iter1.md](README_iter1.md)
93
+
94
+ ### 🔄 Iteration 2
95
+ - **Model File**: `pytorch_model_iter2.bin`
96
+ - **Config**: `config_iter2.json`
97
+ - **Documentation**: [README_iter2.md](README_iter2.md)
98
+
99
+ ## Quick Start
100
+
101
+ ### Load Iteration 1
102
+ ```python
103
+ import torch
104
+ checkpoint = torch.load("pytorch_model_iter1.bin", map_location="cpu")
105
+ ```
106
+
107
+ ### Load Iteration 2
108
+ ```python
109
+ import torch
110
+ checkpoint = torch.load("pytorch_model_iter2.bin", map_location="cpu")
111
+ ```
112
 
113
  ## Model Architecture
114
 
 
121
  - **Input Channels**: 6 (3 real + 3 imaginary spectrogram channels)
122
  - **Output Classes**: 4 (noise, P, S, PS)
123
 
 
 
 
124
  ## Citation
125
 
126
  If you use this model in your research, please cite:
 
140
  This model is licensed under the MIT License.
141
  """
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  def upload_model_to_hf(
144
  checkpoint_path: str,
145
  config_path: str = None,
146
  repo_name: str = "PhaseNet-TF_Alaska",
147
  username: str = None,
148
+ token: str = None,
149
+ version: str = None,
150
+ upload_main_readme: bool = False
151
  ):
152
  """Upload model to Hugging Face Hub"""
153
 
 
179
  print(f"Error creating repository: {e}")
180
  return
181
 
182
+ # Determine file paths based on version
183
+ if version:
184
+ model_path = f"pytorch_model_{version}.bin"
185
+ config_path_in_repo = f"config_{version}.json"
186
+ readme_path_in_repo = f"README_{version}.md"
187
+ print(f"Uploading version {version} to {repo_id}")
188
+ else:
189
+ model_path = "pytorch_model.bin"
190
+ config_path_in_repo = "config.json"
191
+ readme_path_in_repo = "README.md"
192
+ print(f"Uploading to {repo_id}")
193
+
194
  # Upload checkpoint
195
+ print(f"Uploading model checkpoint as {model_path}...")
196
  upload_file(
197
  path_or_fileobj=checkpoint_path,
198
+ path_in_repo=model_path,
199
  repo_id=repo_id,
200
  token=token
201
  )
202
 
203
+ # Upload config if provided
204
  if config_path and os.path.exists(config_path):
205
+ config_yaml_path = f"config_{version}.yaml" if version else "config.yaml"
206
+ print(f"Uploading config file as {config_yaml_path}...")
207
  upload_file(
208
  path_or_fileobj=config_path,
209
+ path_in_repo=config_yaml_path,
210
  repo_id=repo_id,
211
  token=token
212
  )
213
 
214
  # Create and upload config.json
215
+ config_json = create_config_json(checkpoint_path, version)
216
  config_json_path = "config.json"
217
  with open(config_json_path, 'w') as f:
218
  json.dump(config_json, f, indent=2)
219
 
220
  upload_file(
221
  path_or_fileobj=config_json_path,
222
+ path_in_repo=config_path_in_repo,
223
  repo_id=repo_id,
224
  token=token
225
  )
226
 
227
  # Create and upload README.md
228
+ model_card = create_model_card(version)
229
+ if version:
230
+ model_card += f'checkpoint = torch.load("pytorch_model_{version}.bin", map_location="cpu")'
231
+ else:
232
+ model_card += 'checkpoint = torch.load("pytorch_model.bin", map_location="cpu")'
233
+
234
+ model_card += """
235
+
236
+ ## Citation
237
+
238
+ If you use this model in your research, please cite:
239
+
240
+ ```bibtex
241
+ @article{jie2025background,
242
+ title={Background Seismicity and Aftershocks of the 2020-2021 Large Earthquakes at the Alaska Peninsula Revealed by a Deep-learning-based Catalog},
243
+ author={Jie, Yaqi and Wei, Songqiao Shawn and Zhu, Weiqiang and Freymueller, Jeffrey Todd and Elliott, Julie},
244
+ journal={Authorea Preprints},
245
+ year={2025},
246
+ publisher={Authorea}
247
+ }
248
+ ```
249
+
250
+ ## License
251
+
252
+ This model is licensed under the MIT License.
253
+ """
254
+
255
  readme_path = "README.md"
256
  with open(readme_path, 'w') as f:
257
  f.write(model_card)
258
 
259
  upload_file(
260
  path_or_fileobj=readme_path,
261
+ path_in_repo=readme_path_in_repo,
262
  repo_id=repo_id,
263
  token=token
264
  )
265
 
266
+ # Upload main README if requested
267
+ if upload_main_readme:
268
+ print("Uploading main README.md...")
269
+ main_readme = create_main_readme()
270
+ main_readme_path = "main_README.md"
271
+ with open(main_readme_path, 'w') as f:
272
+ f.write(main_readme)
273
+
274
+ upload_file(
275
+ path_or_fileobj=main_readme_path,
276
+ path_in_repo="README.md",
277
+ repo_id=repo_id,
278
+ token=token
279
+ )
280
+ os.remove(main_readme_path)
281
+
282
  # Clean up temporary files
283
  os.remove(config_json_path)
284
  os.remove(readme_path)
285
 
286
  print(f"Model uploaded successfully to https://huggingface.co/{repo_id}")
287
+ if version:
288
+ print(f"Files uploaded: {model_path}, {config_path_in_repo}, {readme_path_in_repo}")
289
 
290
  if __name__ == "__main__":
291
  import argparse
 
296
  parser.add_argument("--repo-name", default="PhaseNet-TF_Alaska", help="Repository name")
297
  parser.add_argument("--username", help="Hugging Face username (optional if already logged in)")
298
  parser.add_argument("--token", help="Hugging Face token (optional if already logged in)")
299
+ parser.add_argument("--version", help="Version suffix for file naming (e.g., iter1, iter2, v1, v2)")
300
+ parser.add_argument("--main-readme", action="store_true", help="Upload main README that showcases both versions")
301
 
302
  args = parser.parse_args()
303
 
 
306
  config_path=args.config,
307
  repo_name=args.repo_name,
308
  username=args.username,
309
+ token=args.token,
310
+ version=args.version,
311
+ upload_main_readme=args.main_readme
312
  )