Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running #38

Open
zy-lazytitan opened this issue Aug 16, 2024 · 3 comments

Comments

@zy-lazytitan
Copy link

I've configured the environment, then ran the code python run_cf3dgs.py -s data/Tanks/Francis/ --mode train --data_type tanks. It reported an error:

Traceback (most recent call last):
File "/home/l/disk_4T/zz/CF-3DGS/run_cf3dgs.py", line 13, in
from trainer.cf3dgs_trainer import CFGaussianTrainer
File "/home/l/disk_4T/zz/CF-3DGS/trainer/cf3dgs_trainer.py", line 51, in
from utils.vis_utils import interp_poses_bspline, generate_spiral_nerf, plot_pose
File "/home/l/disk_4T/zz/CF-3DGS/utils/vis_utils.py", line 16, in
from evo.tools import plot
File "/home/l/anaconda3/envs/cf3dgs/lib/python3.10/site-packages/evo/tools/plot.py", line 83, in
apply_settings(SETTINGS)
File "/home/l/anaconda3/envs/cf3dgs/lib/python3.10/site-packages/evo/tools/plot.py", line 63, in apply_settings
mpl.use(settings.plot_backend)
File "/home/l/anaconda3/envs/cf3dgs/lib/python3.10/site-packages/matplotlib/init.py", line 1233, in use
plt.switch_backend(name)
File "/home/l/anaconda3/envs/cf3dgs/lib/python3.10/site-packages/matplotlib/pyplot.py", line 279, in switch_backend
raise ImportError(
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running

Is this because the version of "evo" is wrong? My evo version is 1.29.0 and the matplotlib version is 3.7.0, as mentioned in requirement.txt

@pdd-show
Copy link

I ran into the same problem, saying 'ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running ',
My ubuntu is Ubuntu 22.04 LTS server, other issues say that the matplotlib version is too high, I reduced to version 3.7, but it did not work.
Or add 'matplotlib.use('Agg')' to the py file, which doesn't work either.

@massyzs
Copy link

massyzs commented Aug 20, 2024

Fixed:
Please remove all evo related lib and only rely on matplotlib. And then:
Use code generated by GPT: (I just get tired of configuring this env.)

def align_trajectories(ref_poses, est_poses):
# Example alignment logic (dummy, for actual use, replace with proper transformation logic)
# This assumes both are numpy arrays of shape (N, 3)
est_poses_aligned = copy.deepcopy(est_poses)
# Assuming simple translation alignment (you can adjust this logic as needed)
offset = np.mean(ref_poses - est_poses, axis=0)
est_poses_aligned += offset
return est_poses_aligned

def plot_pose(ref_poses, est_poses, output_path, vid=False):
ref_poses = np.array(ref_poses)
est_poses = np.array(est_poses)

# Align trajectories
traj_ref = ref_poses
traj_est_aligned = align_trajectories(ref_poses, est_poses)

if vid:
    for p_idx in range(len(ref_poses)):
        fig = plt.figure()
        ax = fig.add_subplot(111, projection="3d")

        current_est_aligned = traj_est_aligned[:p_idx + 1]
        current_ref = traj_ref[:p_idx + 1]

        ax.plot(current_ref[:, 0], current_ref[:, 1], current_ref[:, 2], 'b--', label="Ground-truth")
        ax.plot(current_est_aligned[:, 0], current_est_aligned[:, 1], current_est_aligned[:, 2], 'r-', label="Ours (aligned)")

        ax.set_xlabel('X')
        ax.set_ylabel('Y')
        ax.set_zlabel('Z')
        ax.legend()
        ax.view_init(elev=10., azim=45)

        os.makedirs(os.path.join(os.path.dirname(output_path), 'pose_vid'), exist_ok=True)
        pose_vis_path = os.path.join(os.path.dirname(output_path), 'pose_vid', f'pose_vis_{p_idx:03d}.png')
        print(pose_vis_path)
        fig.savefig(pose_vis_path)
        plt.close(fig)

# Static plot
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")

ax.plot(traj_ref[:, 0], traj_ref[:, 1], traj_ref[:, 2], 'b--', label="Ground-truth")
ax.plot(traj_est_aligned[:, 0], traj_est_aligned[:, 1], traj_est_aligned[:, 2], 'r-', label="Ours (aligned)")

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.legend()
ax.view_init(elev=10., azim=45)

pose_vis_path = os.path.join(os.path.dirname(output_path), 'pose_vis.png')
fig.savefig(pose_vis_path)
plt.close(fig)

@pdd-show
Copy link

Fixed: Please remove all evo related lib and only rely on matplotlib. And then: Use code generated by GPT: (I just get tired of configuring this env.)

def align_trajectories(ref_poses, est_poses): # Example alignment logic (dummy, for actual use, replace with proper transformation logic) # This assumes both are numpy arrays of shape (N, 3) est_poses_aligned = copy.deepcopy(est_poses) # Assuming simple translation alignment (you can adjust this logic as needed) offset = np.mean(ref_poses - est_poses, axis=0) est_poses_aligned += offset return est_poses_aligned

def plot_pose(ref_poses, est_poses, output_path, vid=False): ref_poses = np.array(ref_poses) est_poses = np.array(est_poses)

# Align trajectories
traj_ref = ref_poses
traj_est_aligned = align_trajectories(ref_poses, est_poses)

if vid:
    for p_idx in range(len(ref_poses)):
        fig = plt.figure()
        ax = fig.add_subplot(111, projection="3d")

        current_est_aligned = traj_est_aligned[:p_idx + 1]
        current_ref = traj_ref[:p_idx + 1]

        ax.plot(current_ref[:, 0], current_ref[:, 1], current_ref[:, 2], 'b--', label="Ground-truth")
        ax.plot(current_est_aligned[:, 0], current_est_aligned[:, 1], current_est_aligned[:, 2], 'r-', label="Ours (aligned)")

        ax.set_xlabel('X')
        ax.set_ylabel('Y')
        ax.set_zlabel('Z')
        ax.legend()
        ax.view_init(elev=10., azim=45)

        os.makedirs(os.path.join(os.path.dirname(output_path), 'pose_vid'), exist_ok=True)
        pose_vis_path = os.path.join(os.path.dirname(output_path), 'pose_vid', f'pose_vis_{p_idx:03d}.png')
        print(pose_vis_path)
        fig.savefig(pose_vis_path)
        plt.close(fig)

# Static plot
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")

ax.plot(traj_ref[:, 0], traj_ref[:, 1], traj_ref[:, 2], 'b--', label="Ground-truth")
ax.plot(traj_est_aligned[:, 0], traj_est_aligned[:, 1], traj_est_aligned[:, 2], 'r-', label="Ours (aligned)")

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.legend()
ax.view_init(elev=10., azim=45)

pose_vis_path = os.path.join(os.path.dirname(output_path), 'pose_vis.png')
fig.savefig(pose_vis_path)
plt.close(fig)

It worked. Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants