Commit 9e2f6e3c authored by lucasb-eyer's avatar lucasb-eyer
Browse files

More detail on Unary reshaping, See for example #58.

parent 27169fdb
......@@ -55,7 +55,7 @@ You can then set a fixed unary potential in the following way:
```python
U = np.array(...) # Get the unary in some way.
print(U.shape) # -> (5, 640, 480)
print(U.shape) # -> (5, 480, 640)
print(U.dtype) # -> dtype('float32')
U = U.reshape((5,-1)) # Needs to be flat.
d.setUnaryEnergy(U)
......@@ -69,6 +69,15 @@ probabilities `py`, don't forget to `U = -np.log(py)` them.
Requiring the `reshape` on the unary is an API wart that I'd like to fix, but
don't know how to without introducing an explicit dependency on numpy.
**Note** that the `nlabels` dimension is the first here before the reshape;
you may need to move it there before reshaping if that's not already the case,
like so:
```python
print(U.shape) # -> (480, 640, 5)
U = U.transpose(2, 0, 1).reshape((5,-1))
```
### Getting a Unary
There's two common ways of getting unary potentials:
......@@ -251,6 +260,15 @@ This is a pretty [co](https://github.com/lucasb-eyer/pydensecrf/issues/52)mm[on]
It means exactly what it says: you are passing a `double` but it wants a `float`.
Solve it by, for example, calling `d.setUnaryEnergy(U.astype(np.float32))` instead of just `d.setUnaryEnergy(U)`, or using `float32` in your code in the first place.
My results are all pixelated like [MS Paint's airbrush tool](http://lmgtfy.com/?q=MS+Paint+Airbrush+tool)!
----------------------------------------------------------
You screwed up reshaping somewhere and treated the class/label dimension as spatial dimension.
This is you misunderstanding NumPy's memory layout and nothing that PyDenseCRF can detect or help with.
This mistake often happens for the Unary, see the [**Note** in that section of the README](https://github.com/lucasb-eyer/pydensecrf#unary-potential).
Maintaining
===========
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment