FLAIR-1 icon indicating copy to clipboard operation
FLAIR-1 copied to clipboard

Re-use example

Open kheinzz opened this issue 1 year ago • 4 comments

Hi,

Thank you for your work and making it available.

Would it be possible to provide an example of how to perform inference using the model you provided on an image? I imagine a common use case would be applying the Cosia model to older BD_ortho images. Providing a detailed example on Google Colab could make the process much more accessible.

By advance thanks for your answer !

kheinzz avatar Dec 13 '24 13:12 kheinzz

Dear @kheinzz ,

Thank you for your feedback. I note the interest in a notebook, but we are currently working on a new version of the code, and this is not possible in the short term.

To perform an inference, you need to use the flair-detect module by pointing to the image of your choice (from the BD Ortho) and to the model downloaded, for example, from the HF page (https://huggingface.co/collections/IGNF/flair-models-landcover-semantic-segmentation-65bb67415a5dbabc819a95de).

The README details the arguments to be given to the flair-1-config-detect.yaml configuration file.

If, for example, you use this model: https://huggingface.co/IGNF/FLAIR-INC_rgbie_15cl_resnet34-unet the configuration file would be, for example:

output_path: whatever
output_name: whatever

input_img_path:  ../path/to/raster/file.tif
channels: [1, 2, 3, 4, 5]

img_pixels_detection: 512
margin: 128
output_type: "argmax"
n_classes: 19


model_weights: ../path/to/model/weights/FLAIR-INC_rgbie_15cl_resnet34-unet_weights.pth
model_framework: 
    model_provider: SegmentationModelsPytorch
    
    HuggingFace:
        org_model: 
    SegmentationModelsPytorch:
        encoder_decoder: resnet34_unet


batch_size: 4
use_gpu: true
num_worker: 2

write_dataframe: False

norma_task: 
  - norm_type: custom 
    norm_means: [105.08, 110.87, 101.82, 106.38, 53.26]
    norm_stds: [52.17, 45.38, 44, 39.69, 79.3]

the you would call

flair-detect --conf=path/to/flair-1-config-detect.yaml

agarioud avatar Dec 16 '24 11:12 agarioud

Hi Anatol, Thank you for your kind and quick reply—it worked like a charm !

kheinzz avatar Dec 17 '24 08:12 kheinzz

Hi, thank you for your amazing work. I just want to run inference on an RGB image without any geometry feature. But I got error "ValueError: Unknown column geometry". DO you have any suggestion about that? Thank you

axin1301 avatar Jan 18 '25 19:01 axin1301

Hello @axin1301, flair-detect uses the rasterio library and geographical information from the input raster to produce overlapping inferences. Hence you get this error. Apart from modifying the code to work in the pixel space to calculate the slicing of the input raster, you could try to dummy georeference your image to make it work.

agarioud avatar Jan 20 '25 18:01 agarioud