Commit 43ff622f authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Fixed imports

parent 3a985616
Pipeline #58996 failed with stages
in 20 minutes and 17 seconds
......@@ -11,10 +11,10 @@ BACKBONE=iresnet34
BACKBONE=iresnet50
./bin/bob bio demographics regularization-level-fairness vgg2 $BACKBONE \
/idiap/temp/tpereira/2.FRDemographics/regularization/models/contrastive_orthogonality/$VGG_TYPE/$BACKBONE/model.pth \
/idiap/temp/tpereira/2.FRDemographics/regularization/experiments/contrastive_orthogonality/$VGG_TYPE/$BACKBONE/ \
-l sge
#./bin/bob bio demographics regularization-level-fairness vgg2 $BACKBONE \
# /idiap/temp/tpereira/2.FRDemographics/regularization/models/contrastive_orthogonality/$VGG_TYPE/$BACKBONE/model.pth \
# /idiap/temp/tpereira/2.FRDemographics/regularization/experiments/contrastive_orthogonality/$VGG_TYPE/$BACKBONE/ \
# -l sge
BACKBONE=iresnet100
......
BASE_PATH=/idiap/temp/tpereira/2.FRDemographics/regularization/models/contrastive/mobio-male-female/
#COMMAND=./bob/bio/demographics/script/train_regularization_level_fairness_commands.py
BACKBONE=iresnet50
jman submit --name C.IRESNET50 -q gpu --sge-extra-args="-l hostname=vgni001|vgni00[1-9]|vgni01[0-9]|vgni02[0-9]|vgni03[0-2]|vgnh00[1-8]|vgng00[1-8]|vgnf00[1-9]|vgnf01[1-6]" -- ./bin/bob bio demographics train-regularization-level-fairness train-contrastive \
$BASE_PATH/$BACKBONE \
--database ./bob/bio/demographics/config/train/databases/mobio/mobio-male-female.py \
--identity-backbone ./bob/bio/demographics/config/train/backbones/$BACKBONE.py \
--training-config ./bob/bio/demographics/config/train/training_configs/regular_sgd_crossentropy.py \
--max-epochs 50 --batch-size 64 \
--max-positive-pairs-per-subject 20 --negative-pairs-per-subject 20
BACKBONE=iresnet100
jman submit --name C.IRESNET100 -q gpu --sge-extra-args="-l hostname=vgni001|vgni00[1-9]|vgni01[0-9]|vgni02[0-9]|vgni03[0-2]|vgnh00[1-8]|vgng00[1-8]|vgnf00[1-9]|vgnf01[1-6]" -- ./bin/bob bio demographics train-regularization-level-fairness train-contrastive \
$BASE_PATH/$BACKBONE \
--database ./bob/bio/demographics/config/train/databases/mobio/mobio-male-female.py \
--identity-backbone ./bob/bio/demographics/config/train/backbones/$BACKBONE.py \
--training-config ./bob/bio/demographics/config/train/training_configs/regular_sgd_crossentropy.py \
--max-epochs 50 --batch-size 64 \
--max-positive-pairs-per-subject 20 --negative-pairs-per-subject 20
BACKBONE=iresnet34
#jman submit --name C.IRESNET34 -q gpu --sge-extra-args="-l hostname=vgni001|vgni00[1-9]|vgni01[0-9]|vgni02[0-9]|vgni03[0-2]" -- ./bin/bob bio demographics train-regularization-level-fairness train-contrastive \
# $BASE_PATH/$BACKBONE \
# --database ./bob/bio/demographics/config/train/databases/mobio/mobio-male-female.py \
# --identity-backbone ./bob/bio/demographics/config/train/backbones/$BACKBONE.py \
# --training-config ./bob/bio/demographics/config/train/training_configs/regular_sgd_crossentropy.py \
# --max-epochs 50 --batch-size 128 \
# --max-positive-pairs-per-subject 20 --negative-pairs-per-subject 20
......@@ -12,7 +12,7 @@ jman submit --name VGG2-C.IND.IRESNET50 -q gpu --sge-extra-args="-l hostname=vgn
--identity-backbone ./bob/bio/demographics/config/train/backbones/$BACKBONE.py \
--demographic-backbone-checkpoint /idiap/temp/tpereira/2.FRDemographics/regularization/models/demographic/vgg2-short/iresnet50/model.pth \
--demographic-backbone ./bob/bio/demographics/config/train/demographic_backbones/iresnet50.py \
--max-epochs 5 --batch-size 64 \
--max-epochs 1 --batch-size 64 \
--max-positive-pairs-per-subject 3 --negative-pairs-per-subject 2
......@@ -24,7 +24,7 @@ jman submit --name VGG2-C.IND.IRESNET100 -q gpu --sge-extra-args="-l hostname=vg
--identity-backbone ./bob/bio/demographics/config/train/backbones/$BACKBONE.py \
--demographic-backbone-checkpoint /idiap/temp/tpereira/2.FRDemographics/regularization/models/demographic/vgg2-short/iresnet50/model.pth \
--demographic-backbone ./bob/bio/demographics/config/train/demographic_backbones/iresnet50.py \
--max-epochs 5 --batch-size 64 \
--max-epochs 1 --batch-size 64 \
--max-positive-pairs-per-subject 3 --negative-pairs-per-subject 2
......
......@@ -356,7 +356,7 @@ class ContrastiveIndependenceModel(pl.LightningModule):
orthogonality_loss,
Mine(T(embedding_size, embedding_size)),
]
self.regularizer_weights = [0.1, 0.1]
self.regularizer_weights = [0.05, 0.05]
else:
self.regularizers = regularizers
......@@ -409,7 +409,7 @@ class ContrastiveIndependenceModel(pl.LightningModule):
# Applying the orthogonality loss only on the positive pairs
positive_indexes = torch.where(label == 1)[0]
orthogonality_loss = 0
for i, (r, r_w) in enumerate(zip(self.regularizers, self.regularizer_weights)):
l_a = r(
......@@ -463,6 +463,6 @@ class ContrastiveIndependenceModel(pl.LightningModule):
return torch.optim.SGD(
self.facerec_backbone.parameters(),
lr=1e-3,
lr=1e-4,
momentum=0.9,
)
......@@ -144,8 +144,8 @@ def standard_report(
assert len(titles) == len(negatives_dev)
assert len(titles) == len(negatives_eval)
for i, (n_dev, p_dev, n_eval, p_eval) in enumerate(
zip(negatives_dev, positives_dev, negatives_eval, positives_eval)
for i, (n_dev, p_dev, n_eval, p_eval, t) in enumerate(
zip(negatives_dev, positives_dev, negatives_eval, positives_eval, taus)
):
title = None if titles is None else titles[i]
......@@ -175,7 +175,7 @@ def standard_report(
positives_eval=p_eval,
label_lookup_table=lookup_table,
title=title,
pre_computed_taus=taus,
pre_computed_taus=t,
)
pdf.savefig(fig)
......@@ -350,6 +350,16 @@ def casia_africa_report(
negatives_dev, positives_dev, _, _ = load_dev_eval_scores(scores_dev, None)
variables = {
"Female": "Female",
"Male": "Male",
}
lookup_table = dict()
for a in list(variables.keys()):
for b in list(variables.keys()):
lookup_table[f"{a}__{b}"] = f"{variables[a]}-{variables[b]}"
def filter_out(dataframe, age_interval, target_ethnicity):
dataframe = dataframe[
dataframe.probe_age.between(age_interval[0], age_interval[1])
......@@ -387,7 +397,8 @@ def casia_africa_report(
fmr_thresholds=fmr_thresholds,
percentile=percentile,
titles=titles,
lookup_table=None,
lookup_table=lookup_table,
heatmap_reference_fmr=3,
)
......@@ -400,6 +411,20 @@ def rfw_report(
possible_races=["Asian", "African", "Caucasian", "Indian"],
):
variables = {
"Asian": "Asian",
"African": "African",
"Caucasian": "Caucasian",
"Indian": "Indian",
}
lookup_table = dict()
for a in list(variables.keys()):
for b in list(variables.keys()):
lookup_table[f"{a}__{b}"] = f"{variables[a]}-{variables[b]}"
variable_suffix = "race"
possible_genders = ["male", "female"]
variable_suffix = "race"
......@@ -420,11 +445,11 @@ def rfw_report(
output_filename + f"_{gender}.pdf",
variable_suffix,
negatives_eval=negatives_dev,
positives_eval=negatives_dev,
positives_eval=positives_dev,
fmr_thresholds=fmr_thresholds,
percentile=percentile,
titles=titles,
lookup_table=None,
lookup_table=lookup_table,
)
......
......@@ -247,11 +247,14 @@ def compute_fmr_fnmr_tradeoff(
return negatives_eval is not None and positives_eval is not None
# Computing decision thresholds if we have any FMR
taus = (
compute_fmr_thresholds(negatives_dev, fmr_thresholds)
if pre_computed_taus
else pre_computed_taus
)
if pre_computed_taus is None:
taus = (
compute_fmr_thresholds(negatives_dev, fmr_thresholds)
if pre_computed_taus
else pre_computed_taus
)
else:
taus = pre_computed_taus
# If we have an evaluation set, do the plots with the evaluation set,
# otherwise uses the development set
......
from bob.bio.demographics.datasets import MedsTorchDataset, MorphTorchDataset
from bob.bio.face.pytorch.datasets.demographics import (
MedsTorchDataset,
MorphTorchDataset,
)
# https://pytorch.org/docs/stable/data.html
from torch.utils.data import DataLoader
import pytest
from bob.extension import rc
import os
from bob.learn.pytorch.architectures.iresnet import iresnet34
from bob.learn.pytorch.head import ArcFace, Regular
from bob.bio.demographics.regularizers.independence import (
DemographicRegularHead,
OrthogonalityModel,
......@@ -24,6 +27,8 @@ import bob.io.image
reason="Demographics features directory not available. Please do `bob config set bob.bio.demographics.directory [PATH]` to set the base features path.",
)
def test_orthogonality():
from bob.bio.face.pytorch.head import ArcFace, Regular
from bob.bio.face.pytorch.backbones.iresnet import iresnet34
database_path = os.path.join(
rc.get("bob.bio.demographics.directory"), "meds", "samplewrapper"
......@@ -40,9 +45,9 @@ def test_orthogonality():
# )
train_dataloader = DataLoader(dataset, batch_size=64, shuffle=True)
backbone = iresnet34(
pretrained="/idiap/temp/tpereira/bob/data/pytorch/iresnet-91a5de61/iresnet34-5b0d0e90.pth"
)
backbone = iresnet34()
demographic_backbone = iresnet34()
# list(dataloader.dataset.labels.values())
#####################
......@@ -55,8 +60,8 @@ def test_orthogonality():
######################
## DEMOGRAPHIC
num_class = len(list(train_dataloader.dataset.demographic_keys.values()))
demographic_head = DemographicRegularHead(
feat_dim=backbone.features.num_features, num_class=num_class
demographic_head = ArcFace(
feat_dim=demographic_backbone.features.num_features, num_class=num_class
)
################
......@@ -65,9 +70,15 @@ def test_orthogonality():
# Preparing lightining model
model = OrthogonalityModel(
backbone=backbone,
identity_head=identity_head,
demographic_head=demographic_head,
backbone,
demographic_backbone,
identity_head,
demographic_head,
identity_factor=1.0,
orthogonality_factor=1.0,
backbone_checkpoint_file="model.pth",
demographic_epochs=1,
identity_epochs=1,
loss_fn=torch.nn.CrossEntropyLoss(),
optimizer_fn=optimizer,
)
......@@ -83,11 +94,12 @@ def test_orthogonality():
# debug flags
# limit_train_batches=10, # https://pytorch-lightning.readthedocs.io/en/latest/common/trainer.html#limit-train-batches
# limit_val_batches=1,
amp_level="00", # https://pytorch-lightning.readthedocs.io/en/latest/common/trainer.html#amp-level
# amp_level="00", # https://pytorch-lightning.readthedocs.io/en/latest/common/trainer.html#amp-level
)
trainer.fit(
model=model, train_dataloaders=train_dataloader,
model=model,
train_dataloaders=train_dataloader,
)
......@@ -96,6 +108,8 @@ def test_orthogonality():
reason="Demographics features directory not available. Please do `bob config set bob.bio.demographics.directory [PATH]` to set the base features path.",
)
def test_mine():
from bob.bio.face.pytorch.head import ArcFace, Regular
from bob.bio.face.pytorch.backbones.iresnet import iresnet34
database_path = os.path.join(
rc.get("bob.bio.demographics.directory"), "meds", "samplewrapper"
......@@ -171,7 +185,8 @@ def test_mine():
)
trainer.fit(
model=model, train_dataloaders=train_dataloader,
model=model,
train_dataloaders=train_dataloader,
)
pass
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment