-
Notifications
You must be signed in to change notification settings - Fork 17
WIP: Adding Domain adaptation #51
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
Open
bruce-edelman
wants to merge
21
commits into
master
Choose a base branch
from
domain_adaptation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5b60f95
changes to enable domain adaptation
6339e21
move imports back to save time when not in train/predict mode
1970c9e
fix imports and make sure old version is still same output
a081eb8
replace imports to old locations
a15d1a5
tie loss fcts to model output names for clarity
a9cbf17
try to make pypi publish only happen for changes to main
943a14a
Revert "try to make pypi publish only happen for changes to main"
1802e82
fix small errors
ecb54a6
fix loss bug in masked cce with reduce_all
4aed9a2
add ignore
bb1d967
get Domain adaptation fully working -- some refactoring to clean thin…
5a351b1
cleanup
f9a6668
remove unused import
8a989ee
rework gh actions so it will test installations correctly on PRs and …
f07537f
bump version number
3d0efac
finish bumpign version add badges on README
707f1f3
fix action badge:
e58cd48
no dropout in discriminator branch
7504223
small changes
cc8a1ee
add more plots and training metrics to output
5dcf59d
small changes -- save acc file
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| from diploshic.fvTools import * | ||
| from diploshic.msTools import * | ||
| from diploshic.shicstats import * | ||
| from . import network | ||
| from . import domain_adaptive_dataloader |
This file contains hidden or 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 hidden or 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,54 @@ | ||
| from keras.utils import Sequence | ||
| import numpy as np | ||
| import gc | ||
|
|
||
|
|
||
| class DADiploSHICDataLoader(Sequence): | ||
| def __init__(self, X_src, X_tgt, Y_pred, batch_size): | ||
| self.tgt_data = X_tgt | ||
| self.src_data = X_src | ||
| self.y_pred = Y_pred | ||
|
|
||
| self.batch_size = batch_size | ||
|
|
||
| src_size = self.src_data.shape[0] | ||
| tgt_size = self.tgt_data.shape[0] | ||
|
|
||
| self.no_batch = int(np.floor(np.minimum(src_size, tgt_size) / self.batch_size)) # model sees training sample at most once per epoch | ||
| self.src_pred_idx = np.arange(src_size) | ||
| self.src_discr_idx = np.arange(src_size) | ||
| self.tgt_discr_idx = np.arange(tgt_size) | ||
|
|
||
| np.random.shuffle(self.src_pred_idx) | ||
| np.random.shuffle(self.src_discr_idx) | ||
| np.random.shuffle(self.tgt_discr_idx) | ||
|
|
||
| def __len__(self): | ||
| return self.no_batch | ||
|
|
||
| def on_epoch_end(self): | ||
| np.random.shuffle(self.src_pred_idx) | ||
| np.random.shuffle(self.src_discr_idx) | ||
| np.random.shuffle(self.tgt_discr_idx) | ||
| gc.collect() | ||
|
|
||
| def __getitem__(self, idx): | ||
| pred_batch_idx = self.src_pred_idx[idx*self.batch_size:(idx+1)*self.batch_size] | ||
| discrSrc_batch_idx = self.src_discr_idx[idx*(self.batch_size//2):(idx+1)*(self.batch_size//2)] | ||
| discrTgt_batch_idx = self.tgt_discr_idx[idx*(self.batch_size//2):(idx+1)*(self.batch_size//2)] | ||
|
|
||
| batch_X = np.concatenate((self.src_data[pred_batch_idx], | ||
| self.src_data[discrSrc_batch_idx], | ||
| self.tgt_data[discrTgt_batch_idx])) | ||
| batch_Y_pred = np.concatenate((self.y_pred[pred_batch_idx], | ||
| -1*np.ones((len(discrSrc_batch_idx), self.y_pred.shape[1])), | ||
| -1*np.ones((len(discrTgt_batch_idx), self.y_pred.shape[1])))) | ||
|
|
||
| batch_Y_discr = np.concatenate((-1*np.ones(len(pred_batch_idx)), | ||
| np.zeros(len(discrSrc_batch_idx)), | ||
| np.ones(len(discrTgt_batch_idx)))) | ||
|
|
||
| assert batch_X.shape[0] == self.batch_size*2, (batch_X.shape, self.batch_size*2) | ||
| assert batch_Y_pred.shape[0] == batch_Y_discr.shape[0], (batch_Y_pred.shape, batch_Y_discr.shape) | ||
|
|
||
| return batch_X, {"predictor":batch_Y_pred, "discriminator":batch_Y_discr} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the copy 5x line that should be removed in the future when user passes in empirical target domain data the same length of their training set simulations