YoYo000 / MVSNet

MVSNet (ECCV2018) & R-MVSNet (CVPR2019)
MIT License
1.41k stars 304 forks source link

Process SpawnPoolWorker Problem - Solved #152

Open Yarroudh opened 1 year ago

Yarroudh commented 1 year ago

Hello everyone,

I'm trying to use MVSNet on COLMAP results. I faced some issues when I tried to run python colmap2mvsnet.py --dense_folder <PATH>. I wanted to share with you how I solved this problem in case someone is still struggling with it.

This error typically occurs when the calc_score function is defined in the same module as the code that is being executed by a multiprocessing pool. This is how I solved it:

import numpy

def calc_score(inputs):
    i, j, images, extrinsic, points3d, args = inputs
    id_i = images[i+1].point3D_ids
    id_j = images[j+1].point3D_ids
    id_intersect = [it for it in id_i if it in id_j]
    cam_center_i = -np.matmul(extrinsic[i+1][:3, :3].transpose(), extrinsic[i+1][:3, 3:4])[:, 0]
    cam_center_j = -np.matmul(extrinsic[j+1][:3, :3].transpose(), extrinsic[j+1][:3, 3:4])[:, 0]
    score = 0
    for pid in id_intersect:
        if pid == -1:
            continue
        p = points3d[pid].xyz
        theta = (180 / np.pi) * np.arccos(np.dot(cam_center_i - p, cam_center_j - p) / np.linalg.norm(cam_center_i - p) / np.linalg.norm(cam_center_j - p))
        score += np.exp(-(theta - args.theta0) * (theta - args.theta0) / (2 * (args.sigma1 if theta <= args.theta0 else args.sigma2) ** 2))
    return i, j, score
result = p.map(calc_score, [(i, j, images, extrinsic, points3d, args) for i, j in queue])

This should solve the problem and launch the multiprocessing without errors.