The goal of the SAM Rock Fragmentation repository is to use the recent Segment Anything mask generator model created by MetaAI and implement it with an interface and set of algorithms to calculate the P80 resulting from a blasting.
It is not recommended to use the project in production (not yet) because the SAM model was designed for the detection of objects and not rock fragments as such. However, it is useful to provide a proof of concept for future better projects.
The Segment Anything Model (SAM) produces high quality object masks from input prompts such as points or boxes, and it can be used to generate masks for all objects in an image. It has been trained on a dataset of 11 million images and 1.1 billion masks, and has strong zero-shot performance on a variety of segmentation tasks.
SAM in rocks fragments looks like this:
- The tool was developed using the Streamit library in Python.
- The images used as examples in this repository were extracted from https://data.mendeley.com/datasets/z78ghz96bn/1.
- The model used for the inference is vit_b because it requires less resources, however, with small changes in the code you can use any model you want. for more information see Models Checkpoints.
- The diameter of the red balls of the images is used as a scale reference, therefore it is necessary that the image you are going to use has at least one red ball.
- Currently the tool does not take into consideration the depth of the image, this implementation is likely to be implemented in future versions.
The notebook demo.ipynb has been implemented where the tool can be used through the Google Colab platform, just open this link, Change runtime type to GPU and execute all the cells, finally in the last cell a link will be generated where the tool can be used. Please be patient with the loading times, being a free platform in the cloud it may take some time to run.
app.Streamlit.-.Opera.2023-04-15.01-15-12.mp4
If you want to use your own images just upload them into the images folder generated in Google Colab and reload the page (see the capture).
- Results can be improved by using the SAM vit_h type model which has better results.
- If you have the resources, you can try Fine Tuning the SAM model with images of rock fragments, to increase the quality of the inference in the images.
- It can be combined with other models that detect the depth of the image in order to have better measurements on rock fragments.
- Whatever comes to your mind...
The results are generally good, however in some images they can be complicated to segment for example, the image 41 is a difficult image to segment by SAM due the rocks dimensions:
anything to the dm :)