> For the complete documentation index, see [llms.txt](https://facegsm.gitbook.io/facegsm-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://facegsm.gitbook.io/facegsm-documentation/facegsm/using-custom-model.md).

# Using Custom Model

## Description

User can use their **own custom facial recognition embeddings model** by following [How To](#how-to) section below. If the custom model requires **specific preprocessing input**, FaceGSM provides a placeholder to be edited by the user.

{% hint style="info" %}
By default, FaceGSM will use **FaceNet embedding model** with its preprocess input for all modes
{% endhint %}

{% hint style="info" %}
FaceGSM currently supports only TensorFlow or Keras models (h5 format)
{% endhint %}

## How To

1. Configure`MODEL_PATH` with **custom** **model's file path** and `CUSTOM_PREPROCESS` with **True** in `.env` file
2. Insert your custom preprocessing algorithm in the space provided within `/utils/preprocess_custom.py`
3. FaceGSM will use the **new** **model path** and **custom preprocess** for next attacks

## Example

`Before adding custom preprocessing function:`

```python
def preprocess_input_image_custom(face):
    try:
        # Use tf.cast to change data type to tensor float32
        face = tf.cast(face, tf.float32)
        # Do not change the code above

        # ---------------------------------------------
        # Code your custom preprocessing function here
        # ---------------------------------------------

        # Do not change the code below
        if len(face.shape) == 3:
            face = tf.expand_dims(face, axis=0)
        return face
    except:
        show_error("ERROR_PREPROCESSING")
```

`After adding custom preprocessing function:`

```python
def preprocess_input_image_custom(face):
    try:
        # Use tf.cast to change data type to tensor float32
        face = tf.cast(face, tf.float32)
        # Do not change the code above

        # ---------------------------------------------
        face -= 127.5
        face /= 128
        # ---------------------------------------------

        # Do not change the code below
        if len(face.shape) == 3:
            face = tf.expand_dims(face, axis=0)
        return face
    except:
        show_error("ERROR_PREPROCESSING")
```
