Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge from Qiushi's fork to yewsg/yews: add polarity and focal_mechanism models #18

Merged
merged 275 commits into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
275 commits
Select commit Hold shift + click to select a range
03819dd
Replace MIT license by Apache 2.0
lijunzh Apr 12, 2019
50694af
include license and readme for pip package
lijunzh Apr 12, 2019
8c83e13
add tests for yews.transform.functional
lijunzh Apr 12, 2019
f142a87
try travis from torchvision
lijunzh Apr 12, 2019
076dec9
Add travis.ci badge
lijunzh Apr 12, 2019
01f8d19
Fix bug in travis.yml (#1)
lijunzh Apr 12, 2019
cc5dc0b
update logo color
lijunzh Apr 12, 2019
b43159b
try torchvision’s sphinx setup
lijunzh Apr 12, 2019
ff88395
Update logo
lijunzh Apr 12, 2019
11e2cee
Add appveyor.yml for Windows CI (#3)
lijunzh Apr 14, 2019
2e4703c
add appveyor badge
lijunzh Apr 14, 2019
7538b25
add bages for anaconda cloud and pypi
lijunzh Apr 14, 2019
b37c503
move badge below the title
lijunzh Apr 14, 2019
f74ca1d
remove line between logo and title
lijunzh Apr 14, 2019
8b300c8
Add more test to transforms (#2)
lijunzh Apr 14, 2019
210fa17
Add instructin to install pytorch first
lijunzh Apr 14, 2019
c95ad7f
Update conda command
lijunzh Apr 14, 2019
50e0868
Uploading PyTorch builds to lijunzhu channel
lijunzh Apr 14, 2019
ae94d69
not import yews in docs
lijunzh Apr 14, 2019
7516965
Create initial docs (#4)
lijunzh Apr 15, 2019
6c86d34
use www subdomain for docs
lijunzh Apr 16, 2019
af97b15
Squashed commit of the following:
lijunzh Apr 17, 2019
f10364b
Squashed commit of the following:
lijunzh Apr 17, 2019
b2051a9
Add transform to convert label to int
lijunzh Apr 17, 2019
35a559d
Improve conda installation
lijunzh Apr 17, 2019
1cbd347
Squashed commit of the following:
lijunzh Apr 18, 2019
bf621c6
automate release
lijunzh Apr 18, 2019
4f5bbd3
improve docs.
lijunzh Apr 18, 2019
c6edbc5
move docs to a separate repo.
lijunzh Apr 18, 2019
720b2e8
bump version to 0.0.3
lijunzh Apr 18, 2019
accc005
update logo url
lijunzh Apr 18, 2019
cee62a2
Move metadata from setup.py to setup.cfg
lijunzh Apr 20, 2019
1369b62
improve automation.
lijunzh Apr 20, 2019
a13bfb6
yews get version from pkg installation.
lijunzh Apr 20, 2019
0c69039
Use scipy as an extra feature
lijunzh Apr 20, 2019
ce1587e
fix a bug to version in yews.__init__
lijunzh Apr 20, 2019
8a7fc86
Remove not-runnable code from coverage report.
lijunzh Apr 20, 2019
27fbb3c
add pre-commit-config
lijunzh Apr 20, 2019
255f523
add changelog.rst
lijunzh Apr 20, 2019
4ae530c
change .coveragerc
lijunzh Apr 20, 2019
51d043c
add staticmethod valid() to check path.
lijunzh Apr 20, 2019
cb15b95
refactorizing BaseDataset
lijunzh Apr 21, 2019
ae89583
add smoke test via @pytest.mark.smoke
lijunzh Apr 21, 2019
8ffab7d
modify datasets error msgs.
lijunzh Apr 21, 2019
78b9426
add `yews.datasets.utils` with tests covered 100%
lijunzh Apr 22, 2019
74d9c2b
check end of file
lijunzh Apr 22, 2019
4680031
remove redundant __about__.py
lijunzh Apr 22, 2019
3b50da0
update changelog
lijunzh Apr 22, 2019
9f57f5d
add `datasets.wenchuan`
lijunzh Apr 22, 2019
3f41201
fix code issues.
lijunzh Apr 22, 2019
edadacd
add test to datasets.wenchuan
lijunzh Apr 22, 2019
e3dc9e8
update wenchuan example according to new api
lijunzh Apr 22, 2019
39bc9aa
clean temp files due to broken tests.
lijunzh Apr 22, 2019
9c600ff
try svg for logo image
lijunzh Apr 22, 2019
dca3787
change back to gif
lijunzh Apr 22, 2019
5a71e0c
optimize logo and readme layout for mobile
lijunzh Apr 22, 2019
2a47a41
add memory_limit to control loading of .npy file.
lijunzh Apr 22, 2019
d7864a6
bump version to 0.0.4
lijunzh Apr 22, 2019
6f20664
fix a typo.
lijunzh Apr 22, 2019
e96eb8c
add scipy to host environment
lijunzh Apr 22, 2019
2e5c075
update docs url
lijunzh Apr 22, 2019
943c22e
fix doctring typo
lijunzh Apr 22, 2019
be64d7d
sync meta.yaml and setup.cfg for install and test.
lijunzh Apr 23, 2019
63fd322
avoid downloading large file during test
lijunzh Apr 23, 2019
a88cc8e
explicitly add allow_pickle for older numpy.
lijunzh Apr 23, 2019
a7bafc2
update CHANGELOG.rst
lijunzh Apr 23, 2019
12a0c36
Update installation notes in README.rst
lijunzh Apr 23, 2019
1c9fbf3
Implement original cpic model in the paper.
lijunzh Apr 24, 2019
3a6ad94
create mariana dataset and tools to support it.
lijunzh Apr 27, 2019
b1dd25d
bump version to 0.0.5
lijunzh Apr 27, 2019
7f09cd4
wenchuan dataset released to public
lijunzh Apr 27, 2019
66ba8fa
add numpy verion requirement for pathlib usage
lijunzh Apr 27, 2019
c89c26c
fix test_datasets.py bug
lijunzh Apr 27, 2019
d9df016
add packaged SCSN dataset
lijunzh Apr 28, 2019
73b5849
avoid large downlad on traivs-ci
lijunzh Apr 28, 2019
68f7051
add detection example for mariana dataset
lijunzh May 2, 2019
8a076bd
attempt to add OK dataset in the same way as Mariana
lijunzh May 2, 2019
c8660d6
ignore all model files
lijunzh May 2, 2019
330c3fd
Merge branch 'master' into create_OK_dataset
lijunzh May 2, 2019
94487f2
Merge branch 'master' into detection
lijunzh May 2, 2019
443c094
Merge branch 'master' into new_models_module
lijunzh May 2, 2019
0c2983b
Squashed commit of the following:
lijunzh May 7, 2019
d9d7a48
fix function name
lijunzh May 7, 2019
7e4a8c0
fix bias bug
lijunzh May 7, 2019
3a57f60
save results after training
lijunzh May 7, 2019
a6f5058
save model class name
lijunzh May 7, 2019
efb93c3
Allow save and load checkpoint.
lijunzh May 7, 2019
50d4c66
ignore tags file from ctags.
lijunzh May 8, 2019
600a18f
add resume function during training
lijunzh May 13, 2019
79124f7
add picking
lijunzh May 13, 2019
f4a774d
remove dimension check for numpy waveform
lijunzh May 14, 2019
389e514
rename deploy to cpic
lijunzh May 14, 2019
604a798
Merge branch 'detection'
lijunzh May 14, 2019
30c8d49
Merge branch 'improve_train_module'
lijunzh May 14, 2019
b142ddf
add hubconf for torch.hub module
lijunzh May 14, 2019
e6e1a82
migrate to torch.hub load_url
lijunzh May 14, 2019
6933aca
update cpic model
lijunzh May 14, 2019
38a2290
update wenchuan example for new models.cpic module
lijunzh May 14, 2019
f2da734
fix model_device bug
lijunzh May 14, 2019
d124ff6
test training results save
lijunzh May 14, 2019
6ae3138
fix wenchuan example path bug
lijunzh May 14, 2019
0ffea0a
fix wenchuan result path name
lijunzh May 14, 2019
24aa86e
get filename as staticmethod
lijunzh May 14, 2019
446d336
add ok_transfer example
lijunzh May 14, 2019
8dae14f
fix bug in sac dataset
lijunzh May 14, 2019
20c5900
fix typo in ok transfer
lijunzh May 14, 2019
fb1032c
fix typo in ok transfer
lijunzh May 14, 2019
d9d2c31
add loader to ok dataset
lijunzh May 14, 2019
e94fa4a
fix glob bug for ok transfer
lijunzh May 14, 2019
0fa4cec
change path str for obspy read
lijunzh May 14, 2019
4f2c566
convert path after creating label
lijunzh May 14, 2019
232713c
try to fix appveyor
lijunzh May 14, 2019
c966ff1
install obspy for appveyor
lijunzh May 14, 2019
f3a885b
do not download large file during testing
lijunzh May 14, 2019
2668ee5
use tar instead of tar.bz2 for packaged datasets
lijunzh May 15, 2019
aa5e3c4
use model intead of model_gen for trainer
lijunzh May 15, 2019
9473d89
show accuracy at the end of each epoch
lijunzh May 15, 2019
606bdb9
add cpic model pretrianed on wenchuan dataset
lijunzh May 15, 2019
a52816a
Merge branch 'master' of https://github.com/lijunzh/yews
lijunzh May 15, 2019
26d6716
rename example files
lijunzh May 15, 2019
da0b6a4
save current and best checkpoint during training
lijunzh May 15, 2019
c1ddf50
training from initial model
lijunzh May 15, 2019
1faf882
add scipy as a mandatory dependency
lijunzh May 15, 2019
531049a
new deployment example for Mw 7.5 earthquake in southern pacific
lijunzh May 16, 2019
6705a5f
start a doucment for rbp installation steps.
lijunzh May 19, 2019
33c8296
add miniconda and build pytorch from source
lijunzh May 19, 2019
e890b60
update environmental variable
lijunzh May 20, 2019
6373248
disable qnnpack
lijunzh May 20, 2019
eb4cf4b
fix a bug in applying transform during inference
lijunzh May 20, 2019
fec91d0
bump version before release
lijunzh May 24, 2019
b386d84
correct typo
lijunzh Jun 22, 2019
03951c7
use tensor stack instead array stack
lijunzh Jun 22, 2019
ae57971
update example for sp deployment example
lijunzh Jun 22, 2019
85a6667
add raspberry pi files
lijunzh Jun 22, 2019
51a8486
marian deployment example
lijunzh Jun 22, 2019
e728649
Merge branch 'create_OK_dataset'
lijunzh Jun 22, 2019
3195c37
update cpic with a simplified model
lijunzh Jul 4, 2019
87a6010
update rbp example with plots
lijunzh Jul 4, 2019
c07dc3b
Merge branch 'master' of https://github.com/lijunzh/yews
lijunzh Jul 4, 2019
9e3c07e
add batch_size for deployment
lijunzh Jul 7, 2019
c5c9eea
update rbp example
lijunzh Jul 7, 2019
0f1ca9c
update rbp example with simplified model
lijunzh Jul 7, 2019
8f2b4dd
update rbp example with simplified model
lijunzh Jul 7, 2019
d0e55ce
update rbp example
lijunzh Jul 9, 2019
e449efb
Correct a typo
zjzzqs Jul 11, 2019
a941c70
Merge pull request #5 from lijunzh/zjzzqs-patch
zjzzqs Jul 11, 2019
556c655
Making some utils available outside classes
lijunzh Aug 15, 2019
1142a3f
add example for preparing dataset from file names
lijunzh Aug 15, 2019
522edd6
move old example to experimental
lijunzh Aug 15, 2019
27bc438
reorganize dataset pacakge
lijunzh Aug 15, 2019
bf0e74f
correct typo
lijunzh Aug 16, 2019
1c8a2a5
skipped broken waveforms.
lijunzh Aug 16, 2019
df0fb46
fix bug
lijunzh Aug 16, 2019
0414081
fix test for new dataset package
lijunzh Aug 16, 2019
2c25823
remove unused varialbe.
lijunzh Aug 16, 2019
88e41a0
prepare waveform by groups
lijunzh Aug 16, 2019
7dc27f8
avoid skipping the entire group for one invalid phase.
lijunzh Aug 17, 2019
c1fe60c
merge groups of npys into one
lijunzh Aug 17, 2019
d040eb7
add notes for merging large npy arrays.
lijunzh Aug 19, 2019
dd6b5bc
make some object available on the top level of yews package.
lijunzh Aug 19, 2019
c31b0bd
docs fiex
lijunzh Aug 20, 2019
9d9e09b
fix bugs in example
lijunzh Aug 22, 2019
f74ba10
training example
lijunzh Aug 22, 2019
323d4f6
increase batch size for faster training and validation
lijunzh Aug 22, 2019
9e326aa
increase memory limit to load the entire dataset in memory
lijunzh Aug 22, 2019
d9e6bbb
run logner training
lijunzh Aug 22, 2019
0a0c8d8
Update package structure
lijunzh Nov 1, 2019
6e48a1b
Update conda install pytorch command for testing.
lijunzh Nov 2, 2019
3829323
Local test skip downloading large files.
lijunzh Nov 2, 2019
f8c43a8
Update mmap store code for npy.
lijunzh Nov 2, 2019
d080285
Raise exception when file not exists.
lijunzh Nov 2, 2019
6be71ee
Put a soft link to data inside example directory.
lijunzh Nov 2, 2019
f605d21
Temporarily disable tqdm in exporting data.
lijunzh Nov 2, 2019
da89a13
Update CHANGELOG
lijunzh Nov 2, 2019
c48efed
Fix meta.yaml depdendency
lijunzh Nov 2, 2019
33c09bf
Improve anaconda build process.
lijunzh Nov 4, 2019
cdd087f
Use softlink to data path.
lijunzh Nov 4, 2019
849ce4d
Update URLs to package datasets.
lijunzh Mar 11, 2020
c501e55
change Wenchuan data url from gt to dropbox
zjzzqs Apr 17, 2020
84eea47
add packaged_datasets SCSN_polarity
zjzzqs Apr 18, 2020
f68d1a2
add packaged_datasets SCSN_polarity
zjzzqs Apr 18, 2020
5ac23cf
change MEMORY_LIMIT from 2g to 10g
zjzzqs Apr 18, 2020
5606ea7
add import polarity.py
zjzzqs Apr 18, 2020
43d51f8
add polarity.py
zjzzqs Apr 18, 2020
a7ed9eb
add import numpy to polarity.py
zjzzqs Apr 18, 2020
41eb856
added comment for pull request test
ChujieChen Apr 18, 2020
4f8076a
Merge pull request #1 from ChujieChen/master
zjzzqs Apr 18, 2020
e59a67e
delete commit examples in polarity.py
zjzzqs Apr 18, 2020
1cad706
add wenchuan cpic example
zjzzqs Apr 18, 2020
7977424
add scsn polarity training example
zjzzqs Apr 18, 2020
6693acc
Merge pull request #1 from zjzzqs/master
ChujieChen Apr 19, 2020
65aa625
delete the note of 2d, will see it in the focal_mechanism.py
zjzzqs Apr 19, 2020
cfe3c9f
primitive LSTM model added in polarity.py
ChujieChen Apr 21, 2020
859f289
add Taiwan_focal_mechanism dataset
zjzzqs Apr 21, 2020
765e0b2
add Taiwan_focal_mechanism dataset
zjzzqs Apr 21, 2020
6f8e7cb
add focal_mechanism model
zjzzqs Apr 21, 2020
b2b5eb1
add focal_mechanism model
zjzzqs Apr 21, 2020
dca9078
rename scsn.training.py to scsn_polarity_cnn.training.py
zjzzqs Apr 21, 2020
de770a5
rename scsn.training.py to scsn_polarity_cnn.training.py
zjzzqs Apr 21, 2020
edea810
add taiwan_focal_mechanism.training.py to example
zjzzqs Apr 21, 2020
7179212
change the batch_size and learning rate of this example
zjzzqs Apr 22, 2020
c04cba6
add VGG style fm_v2 into models/focal_mechanism.py
zjzzqs Apr 22, 2020
f879d8b
modified VGG style fm_v2, use dropout(0.1) after each maxpool
zjzzqs Apr 22, 2020
8147ae7
delete unknow label, add vgg style model, remove the last 2 cnn layers
zjzzqs Apr 23, 2020
6bb404a
delete unknow label, add vgg style model, remove the last 2 cnn layers
zjzzqs Apr 23, 2020
3e9922e
add vgg style model for grad-cam, remove the last 2 cnn layers, stop …
zjzzqs Apr 23, 2020
57ea196
add a backup line of using AdamW instead of Adam
zjzzqs Apr 25, 2020
4952abf
working LSTM (bidirectional untested)
ChujieChen Apr 25, 2020
0ccc840
Merge pull request #2 from ChujieChen/develop
ChujieChen Apr 25, 2020
0af73fb
finished LSTM for polarity
ChujieChen Apr 25, 2020
aece550
Merge pull request #3 from ChujieChen/develop
ChujieChen Apr 25, 2020
dba1469
Merge branch 'master' into master
zjzzqs Apr 25, 2020
1c829be
Merge pull request #2 from ChujieChen/master
zjzzqs Apr 25, 2020
1171936
Merge pull request #4 from zjzzqs/master
ChujieChen Apr 26, 2020
28d0c1f
added example for polarity LSTM
ChujieChen Apr 26, 2020
f970c46
fix the indent
zjzzqs Apr 26, 2020
debcef5
Merge pull request #3 from ChujieChen/master
zjzzqs Apr 26, 2020
c41b26f
change the wenchuan example file name
zjzzqs Apr 26, 2020
d394f59
fix indent of polarity.py again
zjzzqs Apr 26, 2020
80e49d4
add a note: please use only 1 gpu to run LSTM, https://github.com/pyt…
zjzzqs Apr 26, 2020
3949d1b
add a note: please use only 1 gpu to run LSTM, https://github.com/pyt…
zjzzqs Apr 26, 2020
1df3fd9
fix the dsets name in the example
zjzzqs Apr 26, 2020
f8dc827
add WeightedRandomSampler to balance the numbers of different labels …
zjzzqs Apr 26, 2020
7cea369
add Taiwan20092010 of cpic into packaged_datasets.py and __init__.py
zjzzqs Apr 27, 2020
a0a98d9
add Taiwan20092010 of cpic into packaged_datasets.py and __init__.py
zjzzqs Apr 27, 2020
fc22fbc
add example for cpic: Taiwan20092010
zjzzqs Apr 27, 2020
4cb6c4d
add vgg style model cpicv3, stop at 4 for grad-cam
zjzzqs Apr 27, 2020
1e464a8
add vgg style model cpicv3, stop at 4 for grad-cam
zjzzqs Apr 27, 2020
0b28b77
vgg style model FmV2 stop at 8*8
zjzzqs Apr 27, 2020
a8e95ee
vgg style model FmV2 stop at 8*8
zjzzqs Apr 27, 2020
6f4014b
update cpic.py and wenchuan_cpic.training.py based on the test of gra…
zjzzqs Apr 28, 2020
d2b0be3
forget why, so just add a comment #wav = wav.astype(float) into src/y…
zjzzqs Apr 28, 2020
3935031
add RemoveMean RemoveTrend Taper BandpassFilter into src/yews/transfo…
zjzzqs Apr 28, 2020
773bae9
add polarity_cnn_lstm from Zijian Li
zjzzqs May 6, 2020
2c717e7
input 600->300
zjzzqs Jun 2, 2020
9120bd9
rm data in example
zjzzqs Jun 2, 2020
4b2ae51
fix super
zjzzqs Jun 2, 2020
1047605
update example
zjzzqs Jun 2, 2020
b2b40f1
update cnn_lstm
zjzzqs Jun 4, 2020
898d3f5
add a line for LSTM which can only use one gpu
zjzzqs Jun 4, 2020
e21445f
need to be updated, how to read the pretrained model
zjzzqs Jul 25, 2020
35d670d
Resolve merge conflict
zjzzqs Jul 28, 2020
20a4124
Resolve merge conflict
zjzzqs Jul 28, 2020
2f27820
delete train.py.bak
zjzzqs Jul 28, 2020
6d84a52
fix bug <<<<<<< ======= >>>>>>>
zjzzqs Aug 1, 2020
2297e5f
recover some image and target
zjzzqs Aug 1, 2020
8805b78
nothing important
zjzzqs Aug 1, 2020
e019e7c
xxxx to null link
zjzzqs Aug 1, 2020
9ed1303
delete the commit of using 1 gpu, in the future, use: device = torch.…
zjzzqs Aug 1, 2020
2dadda1
remove RemoveMean, change Taper and BandpassFilter
zjzzqs Aug 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ matrix:
include:
- python: "3.6"
- python: "3.7"
<<<<<<< HEAD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a text generated by git when solving conflicts. Needs to be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolve. Please check it again. Thanks.

=======
- python: "3.8"
>>>>>>> upstream/master

before_install:
- sudo apt-get update
Expand Down
5 changes: 0 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@ applying deep learning techniques on seismic waveform data.



.. image:: https://travis-ci.org/yewsg/yews.svg?branch=master
:target: https://travis-ci.org/yewsg/yews
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to remove the badges here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolve. Please check it again. Thanks.


.. image:: https://ci.appveyor.com/api/projects/status/32r7s2skrgm9ubva?svg=true
:target: https://ci.appveyor.com/project/lijunzh/yews

.. image:: https://codecov.io/gh/yewsg/yews/branch/master/graph/badge.svg
:target: https://codecov.io/gh/yewsg/yews

.. image:: https://anaconda.org/lijunzhu/yews/badges/version.svg
:target: https://anaconda.org/lijunzhu/yews

Expand Down
1 change: 0 additions & 1 deletion examples/data

This file was deleted.

104 changes: 104 additions & 0 deletions examples/scsn_polarity_cnn.training.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import datetime
import torch
from torch.nn import CrossEntropyLoss
from torch.utils.data import DataLoader
from torch.utils.data import random_split

import yews.datasets as dsets
import yews.transforms as transforms
from yews.train import Trainer

from yews.models import polarity_cnn
model=polarity_cnn


if __name__ == '__main__':

print("Now: start : " + str(datetime.datetime.now()))

# Preprocessing
waveform_transform = transforms.Compose([
#transforms.ZeroMean(),
#transforms.SoftClip(1e-4),
transforms.ToTensor(),
])

# Prepare dataset
dsets.set_memory_limit(10 * 1024 ** 3) # first number is GB
# dset = dsets.Wenchuan(path='/home/qszhai/temp_project/deep_learning_course_project/cpic', download=False,sample_transform=waveform_transform)
dset = dsets.SCSN(path='/data6/scsn/polarity/train_npy', download=False, sample_transform=waveform_transform)

# Split datasets into training and validation
train_length = int(len(dset) * 0.8)
val_length = len(dset) - train_length
train_set, val_set = random_split(dset, [train_length, val_length])

# Prepare dataloaders
train_loader = DataLoader(train_set, batch_size=5000, shuffle=True, num_workers=4)
val_loader = DataLoader(val_set, batch_size=10000, shuffle=False, num_workers=4)

# Prepare trainer
trainer = Trainer(model(), CrossEntropyLoss(), lr=0.01)

# Train model over training dataset
trainer.train(train_loader, val_loader, epochs=100, print_freq=100)
#resume='checkpoint_best.pth.tar')

# Save training results to disk
trainer.results(path='scsn_polarity_results.pth.tar')

# Validate saved model
results = torch.load('scsn_polarity_results.pth.tar')
model = model()
model.load_state_dict(results['model'])
trainer = Trainer(model, CrossEntropyLoss(), lr=0.1)
trainer.validate(val_loader, print_freq=100)

print("Now: end : " + str(datetime.datetime.now()))

import matplotlib.pyplot as plt
import numpy as np

myfontsize1=14
myfontsize2=18
myfontsize3=24

results = torch.load('scsn_polarity_results.pth.tar')

fig, axes = plt.subplots(2, 1, num=0, figsize=(6, 4), sharex=True)
axes[0].plot(results['val_acc'], label='Validation')
axes[0].plot(results['train_acc'], label='Training')

#axes[1].set_xlabel("Epochs",fontsize=myfontsize2)
axes[0].set_xscale('log')
axes[0].set_xlim([1, 100])
axes[0].xaxis.set_tick_params(labelsize=myfontsize1)

axes[0].set_ylabel("Accuracies (%)",fontsize=myfontsize2)
axes[0].set_ylim([0, 100])
axes[0].set_yticks(np.arange(0, 101, 10))
axes[0].yaxis.set_tick_params(labelsize=myfontsize1)

axes[0].grid(True, 'both')
axes[0].legend(loc=4)

#axes[1].semilogx(results['val_loss'], label='Validation')
#axes[1].semilogx(results['train_loss'], label='Training')
axes[1].plot(results['val_loss'], label='Validation')
axes[1].plot(results['train_loss'], label='Training')

axes[1].set_xlabel("Epochs",fontsize=myfontsize2)
axes[1].set_xscale('log')
axes[1].set_xlim([1, 100])
axes[1].xaxis.set_tick_params(labelsize=myfontsize1)

axes[1].set_ylabel("Losses",fontsize=myfontsize2)
axes[1].set_ylim([0.0, 1.0])
axes[1].set_yticks(np.arange(0.0,1.01,0.2))
axes[1].yaxis.set_tick_params(labelsize=myfontsize1)

axes[1].grid(True, 'both')
axes[1].legend(loc=1)

fig.tight_layout()
plt.savefig('Accuracies_train_val.pdf')
116 changes: 116 additions & 0 deletions examples/scsn_polarity_lstm_training.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import datetime
import torch
from torch.nn import CrossEntropyLoss
from torch.utils.data import DataLoader
from torch.utils.data import random_split

import yews.datasets as dsets
import yews.transforms as transforms
from yews.train import Trainer

#from yews.models import cpic
#from yews.models import cpic_v1
#from yews.models import cpic_v2
#cpic = cpic_v1

from yews.models import polarity_v1
from yews.models import polarity_v2
from yews.models import polarity_lstm
polarity=polarity_lstm


if __name__ == '__main__':

print("Now: start : " + str(datetime.datetime.now()))

# Preprocessing
waveform_transform = transforms.Compose([
transforms.ZeroMean(),
#transforms.SoftClip(1e-4),
transforms.ToTensor(),
])

# Prepare dataset
dsets.set_memory_limit(10 * 1024 ** 3) # first number is GB
# dset = dsets.Wenchuan(path='/home/qszhai/temp_project/deep_learning_course_project/cpic', download=False,sample_transform=waveform_transform)
dset = dsets.SCSN_polarity(path='/home/qszhai/temp_project/deep_learning_course_project/first_motion_polarity/scsn_data/train_npy', download=False, sample_transform=waveform_transform)

# Split datasets into training and validation
train_length = int(len(dset) * 0.8)
val_length = len(dset) - train_length
train_set, val_set = random_split(dset, [train_length, val_length])

# Prepare dataloaders
train_loader = DataLoader(train_set, batch_size=5000, shuffle=True, num_workers=4)
val_loader = DataLoader(val_set, batch_size=10000, shuffle=False, num_workers=4)

# Prepare trainer
# trainer = Trainer(cpic(), CrossEntropyLoss(), lr=0.1)
# note: please use only 1 gpu to run LSTM, https://github.com/pytorch/pytorch/issues/21108
model_conf = {"hidden_size": 64}
plt = polarity(**model_conf)
trainer = Trainer(plt, CrossEntropyLoss(), lr=0.001)

# Train model over training dataset
trainer.train(train_loader, val_loader, epochs=50, print_freq=100)
#resume='checkpoint_best.pth.tar')

# Save training results to disk
trainer.results(path='scsn_polarity_results.pth.tar')

# Validate saved model
results = torch.load('scsn_polarity_results.pth.tar')
#model = cpic()
model = plt
model.load_state_dict(results['model'])
trainer = Trainer(model, CrossEntropyLoss(), lr=0.001)
trainer.validate(val_loader, print_freq=100)

print("Now: end : " + str(datetime.datetime.now()))

import matplotlib.pyplot as plt
import numpy as np

myfontsize1=14
myfontsize2=18
myfontsize3=24

results = torch.load('scsn_polarity_results.pth.tar')

fig, axes = plt.subplots(2, 1, num=0, figsize=(6, 4), sharex=True)
axes[0].plot(results['val_acc'], label='Validation')
axes[0].plot(results['train_acc'], label='Training')

#axes[1].set_xlabel("Epochs",fontsize=myfontsize2)
axes[0].set_xscale('log')
axes[0].set_xlim([1, 100])
axes[0].xaxis.set_tick_params(labelsize=myfontsize1)

axes[0].set_ylabel("Accuracies (%)",fontsize=myfontsize2)
axes[0].set_ylim([0, 100])
axes[0].set_yticks(np.arange(0, 101, 10))
axes[0].yaxis.set_tick_params(labelsize=myfontsize1)

axes[0].grid(True, 'both')
axes[0].legend(loc=4)

#axes[1].semilogx(results['val_loss'], label='Validation')
#axes[1].semilogx(results['train_loss'], label='Training')
axes[1].plot(results['val_loss'], label='Validation')
axes[1].plot(results['train_loss'], label='Training')

axes[1].set_xlabel("Epochs",fontsize=myfontsize2)
axes[1].set_xscale('log')
axes[1].set_xlim([1, 100])
axes[1].xaxis.set_tick_params(labelsize=myfontsize1)

axes[1].set_ylabel("Losses",fontsize=myfontsize2)
axes[1].set_ylim([0.0, 1.0])
axes[1].set_yticks(np.arange(0.0,1.01,0.2))
axes[1].yaxis.set_tick_params(labelsize=myfontsize1)

axes[1].grid(True, 'both')
axes[1].legend(loc=1)

fig.tight_layout()
plt.savefig('Accuracies_train_val.pdf')
71 changes: 71 additions & 0 deletions examples/taiwan20092010_cpic.training.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import datetime
import torch
from torch.nn import CrossEntropyLoss
from torch.utils.data import DataLoader
from torch.utils.data import random_split

import yews.datasets as dsets
import yews.transforms as transforms
from yews.train import Trainer

#from yews.models import cpic
from yews.models import cpic_v1
from yews.models import cpic_v2
from yews.models import cpic_v3
cpic = cpic_v3


if __name__ == '__main__':

print("Now: start : " + str(datetime.datetime.now()))

# Preprocessing
waveform_transform = transforms.Compose([
transforms.ZeroMean(),
#transforms.RemoveTrend(),
#transforms.RemoveMean(),
#transforms.Taper(),
#transforms.BandpassFilter(),
#transforms.SoftClip(2e-3),
#1e-2=1/100 100=1% max
#2e-3=4/2048 hist: max = 2048
#import numpy as np;import matplotlib.pyplot as plt;samples=np.load("samples.npy",mmap_mode='r');
#targets=np.load("targets.npy");target.shape
#plt.hist(samples[0:100000,0,:].flatten(), bins=100); plt.ylim([0.1,1.5e8]);plt.show()
transforms.ToTensor(),
])

# Prepare dataset
dsets.set_memory_limit(10 * 1024 ** 3) # first number is GB
dset = dsets.Taiwan20092010(path='/home/qszhai/temp_project/deep_learning_course_project/cpic/Taiwan20092010', download=False, sample_transform=waveform_transform)

# Split datasets into training and validation
train_length = int(len(dset) * 0.8)
val_length = len(dset) - train_length
train_set, val_set = random_split(dset, [train_length, val_length])

# Prepare dataloaders
train_loader = DataLoader(train_set, batch_size=2000, shuffle=True, num_workers=4)
# train_set: bastch_size = targets.shape / 500
val_loader = DataLoader(val_set, batch_size=4000, shuffle=False, num_workers=4)
# train_set: bastch_size : larger is better if the GPU memory is enough.
# num_workers = number of cpu core, but limited by the disk speed. so 8 is good.

# Prepare trainer
trainer = Trainer(cpic(), CrossEntropyLoss(), lr=0.1)

# Train model over training dataset
trainer.train(train_loader, val_loader, epochs=300, print_freq=100)
#resume='checkpoint_best.pth.tar')

# Save training results to disk
trainer.results(path='Taiwan20092010_results.pth.tar')

# Validate saved model
results = torch.load('Taiwan20092010_results.pth.tar')
model = cpic()
model.load_state_dict(results['model'])
trainer = Trainer(model, CrossEntropyLoss(), lr=0.1)
trainer.validate(val_loader, print_freq=100)

print("Now: end : " + str(datetime.datetime.now()))
Loading