Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ venv.bak/
.vscode/*
*.code-workspace

# JetBrains IDEA Template
.idea

# Local storages
data/*
datasets/*/
models/*

# Log files
*.log
*.txt
6 changes: 6 additions & 0 deletions datasets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Using built-in datasets
=======================

ZeroShotEval is provided with 2 build-in datasest:
- AWA2
- CUB
Comment on lines +4 to +6
Copy link
Member

Choose a reason for hiding this comment

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

Что мешает использовать, например, SUN?

Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ CLS:
AMSGRAD: True
DATA:
FEAT_EMB:
PATH: "data/CUB/resnet101/"
PATH: "datasets/CUB/resnet101/"
Copy link
Member

Choose a reason for hiding this comment

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

Все ещё сомневаюсь насчет этого переименования

20 changes: 20 additions & 0 deletions experiment/run_embedding_extractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Script that extracts embeddings from raw data (images, texts) and saves it to
disk for further Zero-Shot experiments. Run this before
`run_zeroshot_experiment.py` to generate data for training.
"""

if __name__ == '__main__':
# STEP 0 - DATA PREPARATION
# (DO IT MANUALLY BEFORE RUNNING THIS SCRIPT)
# Prepare dataset CSV with file names to use for raw data loading.
# --------------------------------------------------------------------------

# STEP 1 - EMBEDDINGS EXTRACTION
# Extract embeddings from raw data with specified NN and save it to
# the disk. Note that embedding extractor can load data as a whole or
# using iterators (to fit into RAM). This step also creates a CSV with
# paths to all embedding files.
# --------------------------------------------------------------------------

pass
90 changes: 90 additions & 0 deletions experiment/run_zeroshot_experiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""Main script-launcher for training of ZSL models."""

import os
from argparse import Namespace
from typing import Callable, Tuple

from fvcore.common.config import CfgNode
from torch.nn import Module

from zeroshoteval.evaluation.classification import classification_procedure
from zeroshoteval.utils.defaults import default_setup
from zeroshoteval.utils.parser import load_config, parse_args
from zeroshoteval.zeroshotnets.build import (
build_zeroshot_train,
build_zeroshot_inference
)
from zeroshoteval.zeroshotnets.cada_vae.cada_vae_inference import CADA_VAE_inference_procedure

# os.chdir("../")


def experiment(cfg: CfgNode) -> None:
"""
Start single experiment with the specified configs. Note that this procedure
requires data embeddings, extracted previously. If you don't have the
extracted embeddings, use the `run_embedding_extractor.py` script.

Args:
cfg(CfgNode): Configs. Details can be found in
zeroshoteval/config/defaults.py
"""

# MODEL TRAINING
# ==============
# Pass extracted embeddings to a zero-shot neural network to train it as an
# embedding extractor.
# --------------------------------------------------------------------------

# Embeddings loading from disk
# TODO: Replace ModalitiesEmbeddingDataset with loader from separate files

# Get training procedure function from registry
train_procedure: Callable[[CfgNode], Module] = build_zeroshot_train(cfg)

# Training
zsl_model: Module = train_procedure(cfg)

# MODEL INFERENCE
# ===============
# Apply trained model to test data and (similar to the prev step) extract
# zero-shot embeddings.
# --------------------------------------------------------------------------

# TODO: replace CADA-VAE with general model

# Get inference procedure function from registry
inference_procedure: Callable[[CfgNode, Module], Tuple[Tuple, Tuple]] = build_zeroshot_inference(cfg)

# Inference
train_data, test_data = inference_procedure(cfg, zsl_model)

# MODEL EVALUATION
# ================
# Pass extracted zero-shot embeddings to one of evaluation tasks (
# classification, clustering, verification, etc.)
# --------------------------------------------------------------------------

# TODO: replace classification procedure with more general evaluation calling
classification_procedure(cfg, train_data, test_data)


def main() -> None:
# Parse arguments
experiment_options: Namespace = parse_args()

# Load default configuration and merge with specific configs from args
cfg: CfgNode = load_config(experiment_options)

# Freeze current config to avoid arbitrary changes
cfg.freeze()

# Perform some basic common setups at the beginning of a job
default_setup(cfg, experiment_options)

# Start the experiment
experiment(cfg)


if __name__ == "__main__":
main()
15 changes: 0 additions & 15 deletions linter.sh.save

This file was deleted.

3 changes: 0 additions & 3 deletions misc/README.md

This file was deleted.

18 changes: 0 additions & 18 deletions misc/awa2_download.sh

This file was deleted.

204 changes: 0 additions & 204 deletions misc/cub_awa_sun_emb_transform.py

This file was deleted.

Loading