Giter Club home page Giter Club logo

softmaxfocalloss's Introduction

softmaxfocalloss

the focal loss in Aritcal Focal Loss for Dense Object Detection

Code is test on MxNet 0.11.0

Installation

  1. Clone the softmaxfocalloss repository, and we'll call the directory that you cloned softmaxfocalloss as ${FOCAL_LOSS_ROOT}.
git clone https://github.com/yuantangliang/softmaxfocalloss.git
  1. Install MXNet:

    3.1 Clone MXNet and checkout to MXNet by

    git clone --recursive https://github.com/dmlc/mxnet.git
    git submodule update
    

    3.2 Copy operators in $(FOCAL_LOSS_ROOT)/source/softmaxfocal_output.xxx by

    cp -r $(FOCAL_LOSS_ROOT)/source/* $(MXNET_ROOT)/src/operator/contrib/
    

    3.3 Compile MXNet

    cd ${MXNET_ROOT}
    make -j $(nproc) USE_OPENCV=1 USE_BLAS=openblas USE_CUDA=1 USE_CUDA_PATH=/usr/local/cuda USE_CUDNN=1
    

    3.4 Install the MXNet Python binding by

    cd python
    sudo python setup.py install
    

Test

  1. run test function to make sure everything is ok by
cd  $(FOCAL_LOSS_ROOT)
python softmaxfocaltest.py

softmaxfocalloss's People

Contributors

yuantangliang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

softmaxfocalloss's Issues

MXNetError: Cannot find argument 'label', Possible Arguments

OS: Ubuntu16.04
MXNET: 0.11.1
OPENCV: 3.3
CUDA 8.0
CUDNN 6.0
`EEEE

ERROR: test_basicSoftMax (main.SoftmaxFocalTest)

Traceback (most recent call last):
File "softmaxfocaltest.py", line 16, in test_basicSoftMax
sym = mx.symbol.SoftmaxFocalOutput(data=self.var_input_data,labels=self.var_label,alphas=(0.25,1,1,1),gamma=2)
File "", line 47, in SoftmaxFocalOutput
File "/home/mxnet/python/mxnet/_ctypes/symbol.py", line 127, in _symbol_creator
ctypes.byref(sym_handle)))
File "/home/mxnet/python/mxnet/base.py", line 143, in check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
MXNetError: Cannot find argument 'data', Possible Arguments:

grad_scale : float, optional, default=1
Scale the gradient by a float factor
ignore_label : float, optional, default=-1
the labels with value equals to ignore_label will be ignored during backward (only works if use_ignore is set to be true).
multi_output : boolean, optional, default=False
If set to true, softmax will applied on axis 1
use_ignore : boolean, optional, default=False
If set to true, the ignore_label value will not contribute to the backward gradient
preserve_shape : boolean, optional, default=False
If true, softmax will applied on the last axis
normalization : {'batch', 'null', 'valid'},optional, default='null'
Normalize the gradient
out_grad : boolean, optional, default=False
Apply weighting from output gradient
gamma : int, optional, default='2'
gamma value in focal softmax
alphas : , optional, default=(0.25,)
alpha value in focal softmax,alpha can be set for each class
, in operator SoftmaxFocalOutput(name="", alphas="(0.25, 1, 1, 1)", gamma="2", data="")

======================================================================
ERROR: test_softamxIgnorLabel (main.SoftmaxFocalTest)

Traceback (most recent call last):
File "softmaxfocaltest.py", line 27, in test_softamxIgnorLabel
sym = mx.symbol.SoftmaxFocalOutput(data=self.var_input_data, label=self.var_label,alphas=(0.25,1,1,1),gamma=2,use_ignore=True,ignore_label =1)
File "", line 47, in SoftmaxFocalOutput
File "/home/mxnet/python/mxnet/_ctypes/symbol.py", line 127, in _symbol_creator
ctypes.byref(sym_handle)))
File "/home/mxnet/python/mxnet/base.py", line 143, in check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
MXNetError: Cannot find argument 'label', Possible Arguments:

grad_scale : float, optional, default=1
Scale the gradient by a float factor
ignore_label : float, optional, default=-1
the labels with value equals to ignore_label will be ignored during backward (only works if use_ignore is set to be true).
multi_output : boolean, optional, default=False
If set to true, softmax will applied on axis 1
use_ignore : boolean, optional, default=False
If set to true, the ignore_label value will not contribute to the backward gradient
preserve_shape : boolean, optional, default=False
If true, softmax will applied on the last axis
normalization : {'batch', 'null', 'valid'},optional, default='null'
Normalize the gradient
out_grad : boolean, optional, default=False
Apply weighting from output gradient
gamma : int, optional, default='2'
gamma value in focal softmax
alphas : , optional, default=(0.25,)
alpha value in focal softmax,alpha can be set for each class
, in operator SoftmaxFocalOutput(name="", alphas="(0.25, 1, 1, 1)", gamma="2", label="", data="", ignore_label="1", use_ignore="True")

======================================================================
ERROR: test_basicSoftMax (main.SoftmaxMultiLabelFocalTest)

Traceback (most recent call last):
File "softmaxfocaltest.py", line 69, in test_basicSoftMax
gamma=2,multi_output=True)
File "", line 47, in SoftmaxFocalOutput
File "/home/mxnet/python/mxnet/_ctypes/symbol.py", line 127, in _symbol_creator
ctypes.byref(sym_handle)))
File "/home/mxnet/python/mxnet/base.py", line 143, in check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
MXNetError: Cannot find argument 'data', Possible Arguments:

grad_scale : float, optional, default=1
Scale the gradient by a float factor
ignore_label : float, optional, default=-1
the labels with value equals to ignore_label will be ignored during backward (only works if use_ignore is set to be true).
multi_output : boolean, optional, default=False
If set to true, softmax will applied on axis 1
use_ignore : boolean, optional, default=False
If set to true, the ignore_label value will not contribute to the backward gradient
preserve_shape : boolean, optional, default=False
If true, softmax will applied on the last axis
normalization : {'batch', 'null', 'valid'},optional, default='null'
Normalize the gradient
out_grad : boolean, optional, default=False
Apply weighting from output gradient
gamma : int, optional, default='2'
gamma value in focal softmax
alphas : , optional, default=(0.25,)
alpha value in focal softmax,alpha can be set for each class
, in operator SoftmaxFocalOutput(name="", data="", label="", alphas="(0.25, 1, 1, 1, 1, 1, 1, 1)", multi_output="True", gamma="2")

======================================================================
ERROR: test_cpuSoftamxIgnorLabel (main.SoftmaxMultiLabelFocalTest)

Traceback (most recent call last):
File "softmaxfocaltest.py", line 80, in test_cpuSoftamxIgnorLabel
gamma=2, use_ignore=True, ignore_label=1,multi_output=True)
File "", line 47, in SoftmaxFocalOutput
File "/home/mxnet/python/mxnet/_ctypes/symbol.py", line 127, in _symbol_creator
ctypes.byref(sym_handle)))
File "/home/mxnet/python/mxnet/base.py", line 143, in check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
MXNetError: Cannot find argument 'label', Possible Arguments:

grad_scale : float, optional, default=1
Scale the gradient by a float factor
ignore_label : float, optional, default=-1
the labels with value equals to ignore_label will be ignored during backward (only works if use_ignore is set to be true).
multi_output : boolean, optional, default=False
If set to true, softmax will applied on axis 1
use_ignore : boolean, optional, default=False
If set to true, the ignore_label value will not contribute to the backward gradient
preserve_shape : boolean, optional, default=False
If true, softmax will applied on the last axis
normalization : {'batch', 'null', 'valid'},optional, default='null'
Normalize the gradient
out_grad : boolean, optional, default=False
Apply weighting from output gradient
gamma : int, optional, default='2'
gamma value in focal softmax
alphas : , optional, default=(0.25,)
alpha value in focal softmax,alpha can be set for each class
, in operator SoftmaxFocalOutput(name="", gamma="2", use_ignore="True", label="", data="", ignore_label="1", alphas="(0.25, 1, 1, 1)", multi_output="True")


Ran 4 tests in 0.002s

FAILED (errors=4)`

What is the size of alphas?

I guess the size of alpha should be equal to the number of classes. I wonder whether we can use a single scalar to set the same alpha for all the classes and use

 mx.symbol.SoftmaxFocalOutput(data=self.var_input_data, label=self.var_label,alphas=(0.25),gamma=2) 

instead of

 mx.symbol.SoftmaxFocalOutput(data=self.var_input_data, label=self.var_label,alphas=(0.25, 0.25, 0.25, 0.25),gamma=2) 

Why alpha is a list? How to use it with my own data?

Why alpha is a list? How to use it with my own data?

In your test code:
sym = mx.symbol.SoftmaxFocalOutput(data=self.var_input_data, label=self.var_label, alphas=(0.25, 1, 1, 1), gamma=2, use_ignore=True, ignore_label=1,multi_output=True)

looking forward to your reply

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.