# Command line usage ```{argparse} :module: rex_xai.config :func: cmdargs_parser :prog: ReX ``` ## Model formats ### Onnx ReX natively understands onnx files. Train or download a model (e.g. [Resnet50](https://github.com/onnx/models/blob/main/validated/vision/classification/resnet/model/resnet50-v1-7.onnx)) and, from this directory, run: ```bash ReX tests/test_data/dog.jpg --model resnet50-v1-7.onnx -vv --output dog_exp.jpg ``` ### Pytorch ReX also works with PyTorch, but you will need to write some custom code to provide ReX with the prediction function and model shape, as well as preprocess the input data. See the sample scripts in `scripts/`. ```bash ReX tests/test_data/dog.jpg --script scripts/pytorch.py -vv --output dog_exp.jpg ``` ## Saving output in a database To store all output in a sqlite database, use: ```bash ReX --model -db ``` ReX will create the db if it does not already exist. It will append to any db with the given name, so be careful not to use the same database if you are restarting an experiment. ReX comes with a number of database functions which allow you to load it as a pandas dataframe for analysis. ## Config ReX looks for the config file `rex.toml` in the current working directory and then `$HOME/.config/rex.toml` on unix-like systems. If you want to use a custom location, use: ```bash ReX --model --config ``` An example config file is included in the repo as `example.rex.toml`. Rename this to `rex.toml` if you wish to use it. ReX will ignore the file `example.rex.toml` is you do not rename it. ### Overriding the config Some options from the config file can be overridden at the command line when calling ReX. In particular, you can change the number of iterations of the algorithm: ```bash ReX --model --iters 5 ``` ## Preprocessing Input data should be transformed in the same way the model's training data was transformed before training. For PyTorch models, you should specify the preprocessing steps in the custom script. See the sample scripts in `scripts/` for examples of using models provided by the [torchvision](https://pytorch.org/vision/stable/index.html) and [timm](https://huggingface.co/docs/timm/index) packages. You can also write a script to load an `onnx` model as well if you have custom preprocessing to do. Otherwise, ReX tries to make reasonable guesses for image preprocessing. This includes resizing the image to match that needed for the model, converting it to a PyTorch tensor, and normalising the data. This can be controlled in `rex.toml`. In the event the the model input is multi-channel and the image is greyscale, then ReX will convert the image to pseudo-RGB. If you want more control over the conversion, you can do the conversion yourself and pass in the converted image.