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

Remove code migrated into Hoplite repository. #710

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 3 additions & 4 deletions agile_modeling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@
"\n",
"from chirp import audio_utils\n",
"from chirp.inference import baw_utils\n",
"from chirp.inference import tf_examples\n",
"from chirp.models import metrics\n",
"from chirp.taxonomy import namespace\n",
"from hoplite.taxonomy import namespace\n",
"from chirp.inference.search import bootstrap\n",
"from chirp.inference.search import search\n",
"from chirp.inference.search import display\n",
"from chirp.inference.classify import classify\n",
"from chirp.inference.classify import data_lib\n",
"from chirp.projects.zoo import model_configs\n",
"from chirp.projects.zoo import zoo_interface\n"
"from hoplite.zoo import model_configs\n",
"from hoplite.zoo import zoo_interface\n"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"from chirp.inference.search import search\n",
"from chirp.inference.search import display\n",
"from chirp.inference.classify import classify\n",
"from chirp.projects.zoo import zoo_interface\n"
"from hoplite.zoo import zoo_interface\n"
]
},
{
Expand Down
1 change: 1 addition & 0 deletions chirp/configs/config_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

"""Define the globals that can be used in configuration files."""

from typing import Any

from chirp import audio_utils
Expand Down
2 changes: 1 addition & 1 deletion chirp/data/bird_taxonomy/bird_taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from chirp.data import filter_scrub_utils as fsu
from chirp.data import tfds_features
from chirp.data.bird_taxonomy import premade_queries
from chirp.taxonomy import namespace_db
from etils import epath
from hoplite.taxonomy import namespace_db
import jax
from jax import numpy as jnp
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion chirp/data/bird_taxonomy/premade_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""A set of premade queries to generate stable data configs."""

from chirp.data import filter_scrub_utils as fsu
from chirp.taxonomy import namespace_db
from hoplite.taxonomy import namespace_db

# SSW_STATS_PATH contains useful statistics for SSW species, used to guide our
# DFS search in chirp.data.sampling_utils.sample_recordings_under_constraints.
Expand Down
2 changes: 1 addition & 1 deletion chirp/data/filter_scrub_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from typing import Any, Dict, NamedTuple, Sequence, Union

from chirp.data import sampling_utils as su
from chirp.taxonomy import namespace_db
from hoplite.taxonomy import namespace_db
import numpy as np
import pandas as pd

Expand Down
2 changes: 1 addition & 1 deletion chirp/data/soundevents/soundevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
from chirp import audio_utils
from chirp.data import filter_scrub_utils as fsu
from chirp.data import tfds_features
from chirp.taxonomy import namespace_db
from etils import epath
from hoplite.taxonomy import namespace_db
from jax import numpy as jnp
import numpy as np
import pandas as pd
Expand Down
2 changes: 1 addition & 1 deletion chirp/data/soundscapes/soundscapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
from chirp.data import tfds_features
from chirp.data.bird_taxonomy import bird_taxonomy
from chirp.data.soundscapes import soundscapes_lib
from chirp.taxonomy import annotations_fns
from etils import epath
from hoplite.taxonomy import annotations_fns
import numpy as np
import pandas as pd
import tensorflow as tf
Expand Down
4 changes: 2 additions & 2 deletions chirp/data/soundscapes/soundscapes_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from typing import Any, Callable, Iterator, Set

from absl import logging
from chirp.taxonomy import namespace
from chirp.taxonomy import namespace_db
from etils import epath
from hoplite.taxonomy import namespace
from hoplite.taxonomy import namespace_db
from jax import numpy as jnp
import numpy as np
import pandas as pd
Expand Down
34 changes: 15 additions & 19 deletions chirp/eval/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@

from absl import logging
from chirp.eval import eval_lib
from chirp.projects.zoo import model_configs
from chirp.projects.zoo import zoo_interface
from chirp.taxonomy import namespace
from chirp.taxonomy import namespace_db
from chirp.train import classifier
from chirp.train import hubert
from chirp.train import separator
from clu import checkpoint
from etils import epath
from hoplite.taxonomy import namespace
from hoplite.taxonomy import namespace_db
from hoplite.zoo import model_configs
from hoplite.zoo import zoo_interface
import jax
from jax import numpy as jnp
import ml_collections
Expand Down Expand Up @@ -142,13 +142,11 @@ def fprop(inputs):

head_index = list(model_bundle.model.num_classes.keys()).index('label')
output_weights = train_state.params[f'Dense_{head_index}']['kernel'].T
self.learned_representations.update(
{
n: w
for n, w in zip(class_list.classes, output_weights)
if n not in self.learned_representation_blocklist
}
)
self.learned_representations.update({
n: w
for n, w in zip(class_list.classes, output_weights)
if n not in self.learned_representation_blocklist
})

def __call__(self, inputs: np.ndarray) -> np.ndarray:
return np.asarray(self.model_callback(inputs))
Expand Down Expand Up @@ -200,13 +198,11 @@ def _load_learned_representations(self):
else:
output_weights = tf.train.load_variable(variables_path, candidates[0])
output_weights = np.squeeze(output_weights)
self.learned_representations.update(
{
n: w
for n, w in zip(class_list.classes, output_weights)
if n not in self.learned_representation_blocklist
}
)
self.learned_representations.update({
n: w
for n, w in zip(class_list.classes, output_weights)
if n not in self.learned_representation_blocklist
})

def __post_init__(self):
logging.info('Loading separation model...')
Expand Down Expand Up @@ -273,7 +269,7 @@ class EmbeddingModelCallback:

def __post_init__(self):
logging.info('Loading separation model...')
model_class = model_configs.MODEL_CLASS_MAP[self.model_key]
model_class = model_configs.get_model_class(self.model_key)
self.loaded_model = model_class(**self.model_config)
# Set the object's call method as the model_callback.
self.model_callback = self.__call__
Expand Down
2 changes: 1 addition & 1 deletion chirp/eval/eval_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from absl import logging
from chirp.data import utils as data_utils
from chirp.models import metrics
from chirp.taxonomy import namespace_db
from hoplite.taxonomy import namespace_db
import jax
import ml_collections
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion chirp/export_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from typing import Sequence

from absl import logging
from chirp.taxonomy import namespace
from hoplite.taxonomy import namespace
from jax.experimental import jax2tf
import tensorflow as tf

Expand Down
2 changes: 1 addition & 1 deletion chirp/inference/classify/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from chirp.inference import tf_examples
from chirp.inference.classify import data_lib
from chirp.models import metrics
from chirp.projects.zoo import zoo_interface
from hoplite.zoo import zoo_interface
import numpy as np
import tensorflow as tf
import tqdm
Expand Down
2 changes: 1 addition & 1 deletion chirp/inference/classify/data_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

from chirp import audio_utils
from chirp.inference import tf_examples
from chirp.projects.zoo import zoo_interface
from etils import epath
from hoplite.zoo import zoo_interface
import numpy as np
import tensorflow as tf
import tqdm
Expand Down
6 changes: 3 additions & 3 deletions chirp/inference/embed_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
from chirp import audio_utils
from chirp import path_utils
from chirp.inference import tf_examples
from chirp.projects.zoo import model_configs
from chirp.projects.zoo import zoo_interface
from etils import epath
from hoplite.zoo import model_configs
from hoplite.zoo import zoo_interface
from ml_collections import config_dict
import numpy as np
import soundfile
Expand Down Expand Up @@ -223,7 +223,7 @@ def __init__(

def setup(self):
if self.embedding_model is None:
model_class = model_configs.MODEL_CLASS_MAP[self.model_key]
model_class = model_configs.get_model_class(self.model_key)
self.embedding_model = model_class.from_config(self.model_config)
if hasattr(self, 'model_key'):
del self.model_key
Expand Down
2 changes: 1 addition & 1 deletion chirp/inference/scann_search_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from chirp import audio_utils
from chirp.inference import embed_lib
from chirp.inference import tf_examples
from chirp.projects.zoo import taxonomy_model_tf
from etils import epath
from hoplite.zoo import taxonomy_model_tf
from ml_collections import config_dict
import numpy as np
import tensorflow as tf
Expand Down
8 changes: 4 additions & 4 deletions chirp/inference/search/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
from chirp.inference import embed_lib
from chirp.inference import tf_examples
from chirp.inference.search import search
from chirp.projects.zoo import model_configs
from chirp.projects.zoo import zoo_interface
from etils import epath
from hoplite.zoo import model_configs
from hoplite.zoo import zoo_interface
from ml_collections import config_dict
import tensorflow as tf

Expand All @@ -52,9 +52,9 @@ class BootstrapState:

def __post_init__(self):
if self.embedding_model is None:
self.embedding_model = model_configs.MODEL_CLASS_MAP[
self.embedding_model = model_configs.get_model_class(
self.config.model_key
].from_config(self.config.model_config)
).from_config(self.config.model_config)
self.create_embeddings_dataset()
if self.source_map is None:
if self.baw_auth_token:
Expand Down
2 changes: 1 addition & 1 deletion chirp/inference/search/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from typing import Any, Callable, List, Sequence

from chirp.inference import tf_examples
from chirp.projects.zoo import zoo_interface
from etils import epath
from hoplite.zoo import zoo_interface
import numpy as np
from scipy.io import wavfile
import tensorflow as tf
Expand Down
4 changes: 2 additions & 2 deletions chirp/inference/tests/classify_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

from chirp.inference.classify import classify
from chirp.inference.classify import data_lib
from chirp.projects.zoo import zoo_interface
from chirp.taxonomy import namespace
from hoplite.taxonomy import namespace
from hoplite.zoo import zoo_interface
import numpy as np

from absl.testing import absltest
Expand Down
22 changes: 10 additions & 12 deletions chirp/inference/tests/embed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@
from chirp.inference.search import display
from chirp.inference.search import search
from chirp.models import metrics
from chirp.projects.zoo import models
from chirp.projects.zoo import taxonomy_model_tf
from chirp.projects.zoo import zoo_interface
from chirp.taxonomy import namespace
from etils import epath
from ml_collections import config_dict
from hoplite.taxonomy import namespace
from hoplite.zoo import handcrafted_features_model
from hoplite.zoo import placeholder_model
from hoplite.zoo import zoo_interface
import numpy as np
import tensorflow as tf
import tf_keras

from absl.testing import absltest
from absl.testing import parameterized
Expand Down Expand Up @@ -332,7 +330,7 @@ def test_keyed_write_logits(self):
self.assertEqual(got_example['label'].shape, (0,))

def test_logits_output_head(self):
base_model = models.PlaceholderModel(
base_model = placeholder_model.PlaceholderModel(
sample_rate=22050,
make_embeddings=True,
make_logits=False,
Expand Down Expand Up @@ -566,11 +564,11 @@ def test_load_configs(self, config_name):
self.assertIsNotNone(config)

def test_handcrafted_features(self):
model = models.HandcraftedFeaturesModel.beans_baseline()
model = handcrafted_features_model.HandcraftedFeaturesModel.beans_baseline()

audio = np.zeros([5 * 32000], dtype=np.float32)
outputs = model.embed(audio)
# Five frames because we have 5s of audio with window 1.0 and hope 1.0.
# Five frames because we have 5s of audio with window 1.0 and hop 1.0.
# Beans aggrregation with mfccs creates 20 MFCC channels, and then computes
# four summary statistics for each, giving a total of 80 output channels.
self.assertSequenceEqual([5, 1, 80], outputs.embeddings.shape)
Expand Down Expand Up @@ -603,15 +601,15 @@ def test_beam_pipeline(self):
file_id_depth=0,
)

metrics = embed_lib.build_run_pipeline(
run_metrics = embed_lib.build_run_pipeline(
base_pipeline, output_dir, source_infos, embed_fn
)
counter = metrics.query(
counter = run_metrics.query(
beam.metrics.MetricsFilter().with_name('examples_processed')
)['counters']
self.assertEqual(counter[0].result, 1)

print(metrics)
print(run_metrics)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion chirp/inference/tf_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import os
from typing import Sequence

from chirp.projects.zoo import zoo_interface
from etils import epath
from hoplite.zoo import zoo_interface
import numpy as np
import tensorflow as tf

Expand Down
4 changes: 2 additions & 2 deletions chirp/preprocessing/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from absl import logging
from chirp import audio_utils
from chirp.models import frontend
from chirp.taxonomy import namespace
from chirp.taxonomy import namespace_db
from hoplite.taxonomy import namespace
from hoplite.taxonomy import namespace_db
import jax
from jax import numpy as jnp
import pandas as pd
Expand Down
Loading
Loading