Submitted by Fluff269 t3_104p5k8 in MachineLearning

Hello, I'm looking for a library that trains a CRF model in Python (if Pytorch, that would be even better).

I am working on a semantic segmentation task where we are trying to segment curvilinear structures.

My requirements for the CRF training are a bit specific:

- In my case, the image pixels are not the graph nodes. Instead, since the dataset is curvilinear structures, for every image I have a set of edges (small pieces of the curvilinear structure). I now want to train the CRF on these edge-pieces, that is, the graph nodes will be these edge-pieces. Thus the trained CRF essentially does a binary classification for each of these edge-pieces (that is, whether this edge-piece should be part of the segmentation output or not).

- I need a library where I can specify the unary and pairwise potentials of these edge-pieces in order to train the CRF. As a simple example, the unary potential is the average likelihood of the edge-piece, and the pairwise potential is the angle between two edge-pieces.

- It is not a linear-chain CRF because edge-pieces could be connected to multiple other pieces.

- Currently, I have frozen a deep neural network (DNN) which generates the edge-pieces. If the CRF library is in PyTorch, I could train the DNN and the CRF end-to-end, but if the CRF library is in Python, I would only be able to train the CRF. At this stage, even a Python library would be very helpful.

Some of the existing libraries don't work for my requirement:

- PyDenseCRF : It does not have learnable parameters.

- python-crfsuite : It does not allow me to specify the unary and pairwise potentials.

- pytorch-crf : It does linear-chain CRF while I need a graph one.

- crfasrnn_pytorch : It by default assumes the image pixels as the graph nodes. I cannot specify the unary and pairwise potentials.

If I could get any leads, that would be immensely helpful, thank you.

12

Comments

You must log in or register to comment.

Fluff269 OP t1_j36eqbl wrote

thank you for your reply! :D I'm looking into pystruct now and will try it. Have you tried it before? From the documentation, they use n_nodes in the data format, but for my case, n_nodes keeps changing with every input image. I will try the code nonetheless, but was just wondering to ask if in case you've used it before.

1

OrganicTowel_ t1_j36xaw0 wrote

You can try DGM https://github.com/Project-10/DGM. Although it's in c++, you can construct python bindings and make it work. I've used it for edge classification, something similar to what you're trying to do and it works nicely

1