nmoehrle / mvs-texturing

Algorithm to texture 3D reconstructions from multi-view stereo images
Other
978 stars 338 forks source link

An endless loop occurs during the "Optimizing" phase in "View selection"  #136

Closed KeoChi closed 4 years ago

KeoChi commented 4 years ago

Hello. For the same data,sometimes the following problems occur:

View selection:
    Building BVH from 77224 faces... done. (Took: 46 ms)
        Calculating face qualities 100%... done. (Took 1.45s)                   
        Postprocessing face infos 100%... done. (Took 0.011s)                   
    Maximum quality of a face within an image: 285.9
    Clamping qualities to 70.8531 within normalization.
    Writing data cost file... done.
    Optimizing:
        Time[s] Energy
                ......  .........
                ......  .........
                4000  0
                4000  0
                4001  0
                ......  .........
                ......   ........

An endless loop occurs during the "Optimizing" phase. I can't find the starting value(Time[s] Energy) due to the endless loop. Corresponding code:

 template<typename COSTTYPE, uint_t SIMDWIDTH>
FORCEINLINE
_s_t<COSTTYPE, SIMDWIDTH>
mapMAP<COSTTYPE, SIMDWIDTH>::
optimize(
    std::vector<_iv_st<COSTTYPE, SIMDWIDTH>>& solution,
    const mapMAP_control& control_flow)
throw()
{
    _s_t<COSTTYPE, SIMDWIDTH> obj;

    /* copy some options from control structure */
    m_tree_sampler_algo = control_flow.tree_algorithm;
    m_sample_deterministic = control_flow.sample_deterministic;

    /* initialize seed generator */
    m_seeder.seed(control_flow.initial_seed);

    /* create std modules for uninitialized fields */
    create_std_modules();

    /* check inputs for completeness and various sanity checks */
    if(!check_data_complete())
        throw std::runtime_error("Input data for optimization "
            "incomplete or not sane.");

    /* report on starting the optimization process */
    if(!m_use_callback)
        std::cout << "[mapMAP] "
                << UNIX_COLOR_GREEN
                << "Starting optimization..."
                << UNIX_COLOR_RESET
                << std::endl;

    /* start timer */
    m_time_start = std::chrono::system_clock::now();

    /* initialize current solution */
    const luint_t num_nodes = m_graph->num_nodes();
    m_solution.resize(num_nodes);
    std::fill(m_solution.begin(), m_solution.end(), 0);

    /* find initial solution by tree-optimization w/o dependencies */
    m_objective = initial_labelling();
    record_time_from_start();
    print_status();

    /* check for termination */
    if(check_termination())
    {
        solution.assign(m_solution.begin(), m_solution.end());

        return m_objective;
    }

    /* rapid initial descent by multilevel */
    if(control_flow.use_multilevel)
    {
        m_objective = opt_step_multilevel();
        record_time_from_start();
        print_status();
    }

    /* take spanning tree steps until no more improvements occur */
    luint_t sp_it = 0;

    _s_t<COSTTYPE, SIMDWIDTH> old_objective = m_objective;
    while(control_flow.use_spanning_tree)
    {
        ++sp_it;

        /* check if algorithm needs to terminate this mode */
        if(check_termination())
            break;

        /* execute spanning tree step */
        obj = opt_step_spanning_tree();
        record_time_from_start();

        if(obj < old_objective)
            old_objective = obj;
        else
            break;

        print_status();

        if(control_flow.use_multilevel && sp_it %
            control_flow.spanning_tree_multilevel_after_n_iterations == 0)
        {
            m_objective = opt_step_multilevel();
            record_time_from_start();
            print_status();
        }
    }

    /* lastly, execute (forced) acyclic steps until termination */
    luint_t ac_it = 0;
    while(control_flow.use_acyclic &&
        (!check_termination() || (control_flow.force_acyclic &&
        ac_it < control_flow.min_acyclic_iterations)))
    {
        ++ac_it;

        m_objective = opt_step_acyclic(control_flow.relax_acyclic_maximal);

        record_time_from_start();
        print_status();
    }

    /* output solution */
    solution.assign(m_solution.begin(), m_solution.end());

    /* report on starting the optimization process */
    if(!m_use_callback)
        std::cout << "[mapMAP] "
                << UNIX_COLOR_GREEN
                << "Finished optimization."
                << UNIX_COLOR_RESET
                << std::endl;

    return m_objective;
}

I'm not very familiar with this library mapmap. What are the reasons for this? Thank you!

nmoehrle commented 4 years ago

I believe this is due to an issue when the energy is zero, which should have been resolved already in newer version of mapmap.

KeoChi commented 4 years ago

@nmoehrle Thank you!