API Reference
This section provides an auto-generated API reference for the ibbi
package.
ibbi
Main initialization file for the ibbi package.
create_model(model_name, pretrained=False, **kwargs)
Creates a model from a name.
This factory function is the main entry point for users of the package. It looks up the requested model in the registry, downloads pretrained weights from the Hugging Face Hub if requested, and returns an instantiated model object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name
|
str
|
Name of the model to create. |
required |
pretrained
|
bool
|
Whether to load pretrained weights from the Hugging Face Hub. Defaults to False. |
False
|
**kwargs
|
Any
|
Extra arguments to pass to the model-creating function. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
ModelType |
ModelType
|
An instance of the requested model (e.g., YOLOSingleClassBeetleDetector or YOLOBeetleMultiClassDetector). |
Raises:
Type | Description |
---|---|
KeyError
|
If the requested |
Example
import ibbi
# Create a pretrained single-class detection model
detector = ibbi.create_model("yolov10x_bb_detect_model", pretrained=True)
# Create a pretrained multi-class detection model
multi_class_detector = ibbi.create_model("yolov10x_bb_multi_class_detect_model", pretrained=True)
Source code in src\ibbi\__init__.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
explain_model(model, explain_dataset, background_dataset, num_explain_samples, num_background_samples, max_evals=1000, batch_size=50, image_size=(640, 640), text_prompt=None)
Generates SHAP explanations for a given model. This function is computationally intensive.
Source code in src\ibbi\xai\shap.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
get_dataset(repo_id='IBBI-bio/ibbi_test_data', split='train', **kwargs)
Loads a dataset from the Hugging Face Hub.
This function is a wrapper around datasets.load_dataset
and returns
the raw Dataset object, allowing for direct manipulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo_id
|
str
|
The Hugging Face Hub repository ID of the dataset. Defaults to "IBBI-bio/ibbi_test_data". |
'IBBI-bio/ibbi_test_data'
|
split
|
str
|
The dataset split to use (e.g., "train", "test"). Defaults to "train". |
'train'
|
**kwargs
|
Additional keyword arguments passed directly to
|
{}
|
Returns:
Name | Type | Description |
---|---|---|
Dataset |
Dataset
|
The loaded dataset object from the Hugging Face Hub. |
Raises:
Type | Description |
---|---|
TypeError
|
If the loaded object is not of type |
Example
import ibbi
# Load the default test dataset
test_data = ibbi.get_dataset()
# Iterate through the first 5 examples
for i, example in enumerate(test_data):
if i >= 5:
break
print(example['image'])
Source code in src\ibbi\utils\data.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
list_models(as_df=False)
Displays available models and their key information.
Reads the model summary CSV included with the package and prints it. Can also return the data as a pandas DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
as_df
|
bool
|
If True, returns the model information as a pandas DataFrame. If False (default), prints the information to the console. |
False
|
Returns:
Type | Description |
---|---|
pd.DataFrame or None: A DataFrame if as_df is True, otherwise None. |
Source code in src\ibbi\utils\info.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
plot_explanations(shap_explanation_for_single_image, model, top_k=5, text_prompt=None)
Plots SHAP explanations for a SINGLE image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shap_explanation_for_single_image
|
Explanation
|
A SHAP Explanation object for a SINGLE image.
To get this, index the output of explain_model (e.g., |
required |
model
|
ModelType
|
The model that was explained. |
required |
top_k
|
int
|
The number of top predicted classes to visualize. |
5
|
text_prompt
|
Optional[str]
|
The text prompt, if a GroundingDINOModel was used. |
None
|
Source code in src\ibbi\xai\shap.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|