Skip to content

Commit

Permalink
Remove code which has migrated into Hoplite repository.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 714119621
  • Loading branch information
sdenton4 authored and copybara-github committed Jan 10, 2025
1 parent b414a20 commit c05cf3a
Show file tree
Hide file tree
Showing 91 changed files with 801 additions and 526,602 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,3 @@ jobs:
run: poetry run python -m unittest discover -s chirp/train_tests -p "*test.py"
- name: Test inference with unittest
run: poetry run python -m unittest discover -s chirp/inference/tests -p "*test.py"
- name: Test hoplite with unittest
run: poetry run python -m unittest discover -s chirp/projects/agile2/tests -p "*test.py"
- name: Test agile2 with unittest
run: poetry run python -m unittest discover -s chirp/projects/hoplite/tests -p "*test.py"
5 changes: 1 addition & 4 deletions .github/workflows/ci_pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ jobs:
pip install absl-py
pip install requests
pip install tensorflow-cpu
pip install git+https://github.com/google-research/perch-hoplite.git
pip install git+https://github.com/google-research/perch.git
- name: Test with unittest
run: python -m unittest discover -s chirp/tests -p "*test.py"
- name: Test inference with unittest
run: python -m unittest discover -s chirp/inference/tests -p "*test.py"
- name: Test hoplite with unittest
run: python -m unittest discover -s chirp/projects/agile2/tests -p "*test.py"
- name: Test agile2 with unittest
run: python -m unittest discover -s chirp/projects/hoplite/tests -p "*test.py"
6 changes: 3 additions & 3 deletions agile_modeling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@
"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 perch_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 perch_hoplite.zoo import model_configs\n",
"from perch_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 perch_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,12 +26,12 @@
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
import jax
from jax import numpy as jnp
import numpy as np
import pandas as pd
from perch_hoplite.taxonomy import namespace_db
import tensorflow as tf
import tensorflow_datasets as tfds

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 perch_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
3 changes: 2 additions & 1 deletion chirp/data/filter_scrub_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
# limitations under the License.

"""Utilities to filter/scrub data."""

import enum
import functools
from typing import Any, Dict, NamedTuple, Sequence, Union

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


class MergeStrategy(enum.Enum):
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,11 +24,11 @@
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 jax import numpy as jnp
import numpy as np
import pandas as pd
from perch_hoplite.taxonomy import namespace_db
import tensorflow as tf
import tensorflow_datasets as tfds

Expand Down
7 changes: 5 additions & 2 deletions chirp/data/soundscapes/soundscapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
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
import numpy as np
import pandas as pd
from perch_hoplite.taxonomy import annotations_fns
import tensorflow as tf
import tensorflow_datasets as tfds

Expand All @@ -47,6 +47,8 @@
organization={CEUR}
}
"""


@dataclasses.dataclass
class SoundscapesConfig(bird_taxonomy.BirdTaxonomyConfig):
"""Dataset configuration for Soundscape datasets.
Expand Down Expand Up @@ -93,6 +95,7 @@ class SoundscapesConfig(bird_taxonomy.BirdTaxonomyConfig):
supervised: bool = True
audio_dir = epath.Path('gs://chirp-public-bucket/soundscapes')


class Soundscapes(bird_taxonomy.BirdTaxonomy):
"""DatasetBuilder for soundscapes data."""

Expand Down Expand Up @@ -485,7 +488,7 @@ def _generate_examples(self, segments: pd.DataFrame):
segments = segments.drop(k, axis=1)

def _process_group(
group: tuple[int, tuple[str, pd.DataFrame]]
group: tuple[int, tuple[str, pd.DataFrame]],
) -> Sequence[tuple[str, dict[str, Any]]]:
# Each filename gets a unique ID
recording_id, (filename, segment_group) = group
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,12 +20,12 @@
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 jax import numpy as jnp
import numpy as np
import pandas as pd
from perch_hoplite.taxonomy import namespace
from perch_hoplite.taxonomy import namespace_db
import tensorflow_datasets as tfds
import tqdm

Expand Down
33 changes: 14 additions & 19 deletions chirp/eval/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@

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
Expand All @@ -33,6 +29,9 @@
from jax import numpy as jnp
import ml_collections
import numpy as np
from perch_hoplite.taxonomy import namespace
from perch_hoplite.zoo import model_configs
from perch_hoplite.zoo import zoo_interface
import tensorflow as tf

ConfigDict = ml_collections.ConfigDict
Expand Down Expand Up @@ -142,13 +141,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 +197,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 +268,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
16 changes: 7 additions & 9 deletions chirp/eval/eval_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
from absl import logging
from chirp.data import utils as data_utils
from chirp.models import metrics
from chirp.taxonomy import namespace_db
import jax
import ml_collections
import numpy as np
import pandas as pd
from perch_hoplite.taxonomy import namespace_db
import tensorflow as tf

_EMBEDDING_KEY = 'embedding'
Expand Down Expand Up @@ -691,14 +691,12 @@ class representatives.
eval_search_results = dict()

# Gather all query vectors.
queries = np.stack(
[
learned_representations[ces.class_name]
if ces.class_name in learned_representations
else create_species_query(ces.class_representatives_df['embedding'])
for ces in eval_set.classwise_eval_sets
]
)
queries = np.stack([
learned_representations[ces.class_name]
if ces.class_name in learned_representations
else create_species_query(ces.class_representatives_df['embedding'])
for ces in eval_set.classwise_eval_sets
])

# Perform a matrix-matrix scoring using stacked queries and search corpus
# embeddings.
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,8 +19,8 @@
from typing import Sequence

from absl import logging
from chirp.taxonomy import namespace
from jax.experimental import jax2tf
from perch_hoplite.taxonomy import namespace
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,8 +21,8 @@
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
import numpy as np
from perch_hoplite.zoo import zoo_interface
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,9 +34,9 @@

from chirp import audio_utils
from chirp.inference import tf_examples
from chirp.projects.zoo import zoo_interface
from etils import epath
import numpy as np
from perch_hoplite.zoo import zoo_interface
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,11 +27,11 @@
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 ml_collections import config_dict
import numpy as np
from perch_hoplite.zoo import model_configs
from perch_hoplite.zoo import zoo_interface
import soundfile
import tensorflow as tf

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,10 +22,10 @@
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 ml_collections import config_dict
import numpy as np
from perch_hoplite.zoo import taxonomy_model_tf
import tensorflow as tf

from scann.scam_ops.py import scam_ops_pybind
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,10 +25,10 @@
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 ml_collections import config_dict
from perch_hoplite.zoo import model_configs
from perch_hoplite.zoo import zoo_interface
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
3 changes: 2 additions & 1 deletion chirp/inference/search/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
from typing import Any, Callable, List, Sequence

from chirp.inference import tf_examples
from chirp.projects.zoo import zoo_interface
from etils import epath
import numpy as np
from perch_hoplite.zoo import zoo_interface
from scipy.io import wavfile
import tensorflow as tf
import tqdm
Expand All @@ -33,6 +33,7 @@
@dataclasses.dataclass
class SearchResult:
"""Container for a single search result."""

# Embedding vector.
embedding: np.ndarray
# Raw score for this result.
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,9 +19,9 @@

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
import numpy as np
from perch_hoplite.taxonomy import namespace
from perch_hoplite.zoo import zoo_interface

from absl.testing import absltest
from absl.testing import parameterized
Expand Down
Loading

0 comments on commit c05cf3a

Please sign in to comment.