You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
enhancement: get model name and initialization params externally (#291)
Added a method to externally inject a supergradients ONNX model. By
setting the environment variable `UNSTRUCTURED_DEFAULT_MODEL_NAME` one
can override the default model. By setting the environment variable
`UNSTRUCTURED_DEFAULT_MODEL_INITIALIZE_PARAMS_JSON_PATH`, one can
specify the path to a JSON containing model initialization parameters.
#### Testing:
```python
import os
from unstructured_inference.models.base import get_model
os.environ["UNSTRUCTURED_DEFAULT_MODEL_NAME"] = "detectron2_onnx"
model = get_model()
print(type(model))
```
Output should be `UnstructuredDetectronONNXModel` as opposed to
`UnstructuredYoloXModel`.
```python
from unittest import mock
import os
import json
from unstructured_inference.models.base import get_model
from huggingface_hub import hf_hub_download
label_map = {0: "Blue", 1: "Red"}
model_path = hf_hub_download("unstructuredio/yolo_x_layout", "yolox_tiny.onnx")
json_dict = {"model_path": model_path, "label_map": label_map}
os.environ["UNSTRUCTURED_DEFAULT_MODEL_NAME"] = "yolox"
os.environ["UNSTRUCTURED_DEFAULT_MODEL_INITIALIZE_PARAMS_JSON_PATH"] = "some/fake/path.json"
with mock.patch("builtins.open", mock.mock_open(read_data=json.dumps(json_dict))):
model = get_model()
print(model.layout_classes)
```
Output should be `{0: "Blue", 1: "Red"}` as opposed to the normal YoloX
labels.
0 commit comments