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

Paired multimodal autoencoders (with tests!) #393

Merged
merged 21 commits into from
Nov 13, 2020
Merged

Paired multimodal autoencoders (with tests!) #393

merged 21 commits into from
Nov 13, 2020

Conversation

lucidtronix
Copy link
Collaborator

No description provided.

Copy link
Contributor

@ndiamant ndiamant left a comment

Choose a reason for hiding this comment

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

A few questions, but looks basically ready

tests/conftest.py Show resolved Hide resolved
ml4h/recipes.py Outdated Show resolved Hide resolved
ml4h/plots.py Outdated
figure_path = f'{prefix}/{dtm.name}_{feature}_transform_scalar_{scalar}.png'
if not os.path.exists(os.path.dirname(figure_path)):
os.makedirs(os.path.dirname(figure_path))
plt.savefig(figure_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add new line at eof

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

4got pre-commit

ml4h/plots.py Outdated
Comment on lines 2208 to 2211
axes[i, 0].set_xticks(())
axes[i, 0].set_yticks(())
axes[i, 1].set_xticks(())
axes[i, 1].set_yticks(())
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this equivalent to axes[i, 0].axis('off')?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I hope so

ml4h/models.py Outdated

multimodal_activation = Concatenate()(multimodal_activations)
multimodal_activation = Dense(units=kwargs['dense_layers'][0])(multimodal_activation)
#multimodal_activation = _activation_layer(kwargs['activation'])(multimodal_activation)
Copy link
Contributor

Choose a reason for hiding this comment

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

delete comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

ml4h/models.py Outdated
Comment on lines 1184 to 1201
for left, right in pairs:
kwargs['tensor_maps_in'] = [left]
left_model = make_multimodal_multitask_model(**kwargs)
encode_left = make_hidden_layer_model(left_model, [left], kwargs['hidden_layer'])
h_left = encode_left(inputs[left])

kwargs['tensor_maps_in'] = [right]
right_model = make_multimodal_multitask_model(**kwargs)
encode_right = make_hidden_layer_model(right_model, [right], kwargs['hidden_layer'])
h_right = encode_right(inputs[right])

if pair_loss == 'cosine':
loss_layer = CosineLossLayer(1.0)
elif pair_loss == 'euclid':
loss_layer = L2LossLayer(1.0)

paired_embeddings = loss_layer([h_left, h_right])
multimodal_activations.extend(paired_embeddings)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could the logic of this function be written as a new bottleneck type?
Maybe the problem is that the model factory doesn't return the encoders and decoders?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

right, I think it would be possible, maybe cleaner. I'm seeing a weird bug when I try triplet style models so I think this code is still changing quickly

@lucidtronix
Copy link
Collaborator Author

Lots of cleanup, now this works with multiple pairs and cosine/euclid distance as the loss. Also added tests for the semi-supervised setup. Resurrected the conv_width argument for joint models that incorporate ECG and MRI. Eventually, as Nate suggested, we should fold this into the model factory. Issue to track that work is here #359
abc
Thanks for the review, back to you @ndiamant

@lucidtronix lucidtronix merged commit 5e61ba7 into master Nov 13, 2020
@lucidtronix lucidtronix deleted the sf_pairs branch November 13, 2020 12:16
lucidtronix added a commit that referenced this pull request Jan 13, 2023
Adds recipe `train_paired` for multimodal models with losses to encourage the same embeddings of different modalities.
lucidtronix added a commit that referenced this pull request Jan 13, 2023
Adds recipe `train_paired` for multimodal models with losses to encourage the same embeddings of different modalities.
lucidtronix added a commit that referenced this pull request Jan 13, 2023
Adds recipe `train_paired` for multimodal models with losses to encourage the same embeddings of different modalities.
lucidtronix added a commit that referenced this pull request Jan 13, 2023
Adds recipe `train_paired` for multimodal models with losses to encourage the same embeddings of different modalities.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants