lucasb-eyer / pydensecrf

Python wrapper to Philipp Krähenbühl's dense (fully connected) CRFs with gaussian edge potentials.
MIT License
1.95k stars 417 forks source link

Installation issue #127

Open foundnom opened 2 months ago

foundnom commented 2 months ago

Hi! I encountered an issue while trying to install pydensecrf. The error message is as follows:

pip install pydensecrf
Collecting pydensecrf
  Using cached pydensecrf-1.0rc3.tar.gz (1.0 MB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [296 lines of output]
      /path/to/anaconda3/envs/env_name/lib/python3.10/site-packages/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /tmp/pip-install-tempdir/pydensecrf_unique_id/pydensecrf/densecrf.pxd
        tree = Parsing.p_module(s, pxd, full_module_name)

      Error compiling Cython file:
      ------------------------------------------------------------
      ...

          cdef cppclass PottsCompatibility(LabelCompatibility):
              PottsCompatibility(float) except +

          cdef cppclass DiagonalCompatibility(LabelCompatibility):
              DiagonalCompatibility(const c_VectorXf&) except +
                                          ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pxd:12:36: 'c_VectorXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...

          cdef cppclass DiagonalCompatibility(LabelCompatibility):
              DiagonalCompatibility(const c_VectorXf&) except +

          cdef cppclass MatrixCompatibility(LabelCompatibility):
              MatrixCompatibility(const c_MatrixXf&) except +
                                        ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pxd:15:34: 'c_MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
      cdef extern from "densecrf/include/unary.h":
          cdef cppclass UnaryEnergy:
              pass

          cdef cppclass ConstUnaryEnergy(UnaryEnergy):
              ConstUnaryEnergy(const c_MatrixXf& unary) except +
                                     ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pxd:23:31: 'c_MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...

          cdef cppclass ConstUnaryEnergy(UnaryEnergy):
              ConstUnaryEnergy(const c_MatrixXf& unary) except +

          cdef cppclass LogisticUnaryEnergy(UnaryEnergy):
              LogisticUnaryEnergy(const c_MatrixXf& L, const c_MatrixXf& feature) except +
                                        ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pxd:26:34: 'c_MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...

          cdef cppclass ConstUnaryEnergy(UnaryEnergy):
              ConstUnaryEnergy(const c_MatrixXf& unary) except +

          cdef cppclass LogisticUnaryEnergy(UnaryEnergy):
              LogisticUnaryEnergy(const c_MatrixXf& L, const c_MatrixXf& feature) except +
                                                             ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pxd:26:55: 'c_MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              c_DenseCRF(int N, int M) except +

              # Setup methods.
              # TODO
              #void addPairwiseEnergy(PairwisePotential *potential)
              void addPairwiseEnergy(const c_MatrixXf &features, LabelCompatibility*, KernelType, NormalizationType)
                                           ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pxd:54:37: 'c_MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              # Setup methods.
              # TODO
              #void addPairwiseEnergy(PairwisePotential *potential)
              void addPairwiseEnergy(const c_MatrixXf &features, LabelCompatibility*, KernelType, NormalizationType)
              void setUnaryEnergy(UnaryEnergy *unary)
              void setUnaryEnergy(const c_MatrixXf &unary)
                                        ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pxd:56:34: 'c_MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              # TODO
              #void addPairwiseEnergy(PairwisePotential *potential)
              void addPairwiseEnergy(const c_MatrixXf &features, LabelCompatibility*, KernelType, NormalizationType)
              void setUnaryEnergy(UnaryEnergy *unary)
              void setUnaryEnergy(const c_MatrixXf &unary)
              void setUnaryEnergy(const c_MatrixXf &L, const c_MatrixXf &feature)
                                        ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pxd:57:34: 'c_MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              # TODO
              #void addPairwiseEnergy(PairwisePotential *potential)
              void addPairwiseEnergy(const c_MatrixXf &features, LabelCompatibility*, KernelType, NormalizationType)
              void setUnaryEnergy(UnaryEnergy *unary)
              void setUnaryEnergy(const c_MatrixXf &unary)
              void setUnaryEnergy(const c_MatrixXf &L, const c_MatrixXf &feature)
                                                             ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pxd:57:55: 'c_MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              void setUnaryEnergy(UnaryEnergy *unary)
              void setUnaryEnergy(const c_MatrixXf &unary)
              void setUnaryEnergy(const c_MatrixXf &L, const c_MatrixXf &feature)

              # Inference methods.
              c_MatrixXf inference(int n_iterations)
              ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pxd:60:8: 'c_MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              c_MatrixXf inference(int n_iterations)
              # TODO: Not enabled because it would require wrapping VectorXs (note the `s`)
              #c_VectorXs map(int n_iterations)

              # Step-by-step inference methods.
              c_MatrixXf startInference() const
              ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pxd:65:8: 'c_MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              # TODO: Not enabled because it would require wrapping VectorXs (note the `s`)
              #c_VectorXs map(int n_iterations)

              # Step-by-step inference methods.
              c_MatrixXf startInference() const
              void stepInference(c_MatrixXf &Q, c_MatrixXf &tmp1, c_MatrixXf &tmp2) const
                                 ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pxd:66:27: 'c_MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              # TODO: Not enabled because it would require wrapping VectorXs (note the `s`)
              #c_VectorXs map(int n_iterations)

              # Step-by-step inference methods.
              c_MatrixXf startInference() const
              void stepInference(c_MatrixXf &Q, c_MatrixXf &tmp1, c_MatrixXf &tmp2) const
                                                ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pxd:66:42: 'c_MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              # TODO: Not enabled because it would require wrapping VectorXs (note the `s`)
              #c_VectorXs map(int n_iterations)

              # Step-by-step inference methods.
              c_MatrixXf startInference() const
              void stepInference(c_MatrixXf &Q, c_MatrixXf &tmp1, c_MatrixXf &tmp2) const
                                                                  ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pxd:66:60: 'c_MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              # Step-by-step inference methods.
              c_MatrixXf startInference() const
              void stepInference(c_MatrixXf &Q, c_MatrixXf &tmp1, c_MatrixXf &tmp2) const
              #double gradient( int n_iterations, const ObjectiveFunction & objective, c_VectorXf * unary_grad, c_VectorXf * lbl_cmp_grad, c_VectorXf * kernel_grad=NULL ) const;

              double klDivergence(const c_MatrixXf &Q) const
                                        ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pxd:69:34: 'c_MatrixXf' is not a type identifier
      warning: pydensecrf/densecrf.pyx:20:4: Unreachable code

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              return eigen.MatrixXf().wrap(self._this.inference(niter))

          def startInference(self):
              return eigen.MatrixXf().wrap(self._this.startInference()), eigen.MatrixXf(), eigen.MatrixXf()

          def stepInference(self, MatrixXf Q, MatrixXf tmp1, MatrixXf tmp2):
                                  ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pyx:97:28: 'MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              return eigen.MatrixXf().wrap(self._this.inference(niter))

          def startInference(self):
              return eigen.MatrixXf().wrap(self._this.startInference()), eigen.MatrixXf(), eigen.MatrixXf()

          def stepInference(self, MatrixXf Q, MatrixXf tmp1, MatrixXf tmp2):
                                              ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pyx:97:40: 'MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              return eigen.MatrixXf().wrap(self._this.inference(niter))

          def startInference(self):
              return eigen.MatrixXf().wrap(self._this.startInference()), eigen.MatrixXf(), eigen.MatrixXf()

          def stepInference(self, MatrixXf Q, MatrixXf tmp1, MatrixXf tmp2):
                                                             ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pyx:97:55: 'MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              return eigen.MatrixXf().wrap(self._this.startInference()), eigen.MatrixXf(), eigen.MatrixXf()

          def stepInference(self, MatrixXf Q, MatrixXf tmp1, MatrixXf tmp2):
              self._this.stepInference(Q.m, tmp1.m, tmp2.m)

          def klDivergence(self, MatrixXf Q):
                                 ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pyx:100:27: 'MatrixXf' is not a type identifier

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
                  raise ValueError("Bad shape for pairwise energy (Need (?, {}), got {})".format(self._nvar, (features.shape[0], features.shape[1])))

              self._this.addPairwiseEnergy(eigen.c_matrixXf(features), _labelcomp(compat), kernel, normalization)

          def setUnary(self, Unary u):
              self._this.setUnaryEnergy(u.move())
                                       ^
      ------------------------------------------------------------

      pydensecrf/densecrf.pyx:78:33: ambiguous overloaded method
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-tempdir/pydensecrf_unique_id/setup.py", line 13, in <module>
          ext_modules = cythonize(['pydensecrf/eigen.pyx', 'pydensecrf/densecrf.pyx'])
        File "/path/to/anaconda3/envs/env_name/lib/python3.10/site-packages/Cython/Build/Dependencies.py", line 1154, in cythonize
          cythonize_one(*args)
        File "/path/to/anaconda3/envs/env_name/lib/python3.10/site-packages/Cython/Build/Dependencies.py", line 1321, in cythonize_one
          raise CompileError(None, pyx_file)
      Cython.Compiler.Errors.CompileError: pydensecrf/densecrf.pyx
      Compiling pydensecrf/eigen.pyx because it changed.
      Compiling pydensecrf/densecrf.pyx because it changed.
      [1/2] Cythonizing pydensecrf/densecrf.pyx
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

I am running this in a Conda virtual environment on Ubuntu 22.04. Some additional environment details are as follows:

conda==24.1.2
python==3.10
pip==24.0
Cython==3.0.10
eigen== 0.1.1

Do you have any ideas on this problem?

ShakhzodNP commented 2 months ago

I had same issue, this worked for me: pip install git+https://github.com/lucasb-eyer/pydensecrf.git