Error uploading Plotly

Hello. My code throws an error when trying to upload a Plotly fig into wandb. It shows fine when using fig.show() locally. Error code: ValueError: Media {MyKey} is invalid. Please remove invalid filename characters

Hi @ofplarsen Happy to help you on this one. To further investigate this, could you please provide me the following information:

  • debug-internal.log and debug.log for the affected run. These files are under your local folder wandb/run-_-/logs in the same directory where you’re running your code. These files will help us with more details about this error
  • The code snippet/script you’re running so we can see how you are uploading your plotly figures to wandb
  • Full Stack trace of the error as this can help us look at the rest of the error information

def plot_3d_keypoints(keypoints, model_name, wandb_name, epoch):
# Extract X, Y, and Z coordinates from keypoints
x, z, y = zip(*keypoints)

# Define connections between related keypoints
if model_name == 'mediapipe':
    connections = [(0, 1), (0, 2), (1, 3), (2, 4), (3, 5), (6, 7), (0, 6),
                    (1, 7), (6, 8), (7, 9), (8, 10), (9, 11), (10, 12),
                    (11, 13), (10, 14), (11, 15), (12, 14), (13, 15)]

# Create a Plotly 3D scatter plot
fig = go.Figure()

# Scatter plot for keypoints
fig.add_trace(go.Scatter3d(x=x, y=y, z=z, mode='markers', marker=dict(color='red', size=5)))

# Plot connections
for connection in connections:
    x_vals = [x[connection[0]], x[connection[1]]]
    y_vals = [y[connection[0]], y[connection[1]]]
    z_vals = [z[connection[0]], z[connection[1]]]
    fig.add_trace(go.Scatter3d(x=x_vals, y=y_vals, z=z_vals, mode='lines', line=dict(color='blue')))

# Combine x, y, z values into a single list
all_values = x + y + z

# Find the minimum and maximum values
min_value = min(all_values) - abs(min(all_values) * 0.1)
max_value = max(all_values) + abs(max(all_values) * 0.1)

# Update layout to set axis limits
fig.update_layout(
    scene=dict(
        aspectmode='cube',
        xaxis=dict(title='X', range=[min_value, max_value]),
        yaxis=dict(title='Y', range=[min_value, max_value]),
        zaxis=dict(title='Z', range=[min_value, max_value])
    )
)
#fig.show()
# Log the 3D scatter plot using WandB
try:
    if wandb_name == 'morphed':
        wandb.log({'Model Output: Morphed Keypoints': wandb.Plotly(fig), "epoch": epoch+1})
        #wandb.log({'Test': fig})
    elif wandb_name == 'ground_truth':
        wandb.log({'Ground Truth: Dataset Keypoints': fig, "epoch": epoch+1})
    elif wandb_name == 'hpe_truth':
        wandb.log({'Model Input: Keypoints': fig, "epoch": epoch+1})
    else:
        raise ValueError(f"Invalid wandb_name: {wandb_name}")
except Exception as e:
    print("Wandb bug :PPPPPP")
    print(e)

Error: Media Model Output: Morphed Keypoints is invalid. Please remove invalid filename characters
This is for all figures

Hi @ofplarsen

Thank you for sharing those information. Unfortunately, we are unable to reproduce the issue. The error is suggesting that there is some naming conventions in the chart that is not being parsed correctly. May we know which wandb client version you are using? You can get this by running wandb --version

Could you please try our code below for your comparison. This is how we tried to log it and we didn’t encounter any issues:

import wandb
import plotly.graph_objects as go

def plot_3d_keypoints(keypoints, model_name, epoch):
    # Extract X, Y, and Z coordinates from keypoints
    x, z, y = zip(*keypoints)

    # Define connections between related keypoints
    connections = []
    if model_name == 'mediapipe':
        connections = [
            (0, 1), (0, 2), (1, 3), (2, 4), (3, 5), (6, 7), (0, 6),
            (1, 7), (6, 8), (7, 9), (8, 10), (9, 11), (10, 12),
            (11, 13), (10, 14), (11, 15), (12, 14), (13, 15)
        ]

    # Create a Plotly 3D scatter plot
    fig = go.Figure()

    # Scatter plot for keypoints
    fig.add_trace(go.Scatter3d(x=x, y=y, z=z, mode='markers', marker=dict(color='red', size=5)))

    # Plot connections
    for connection in connections:
        x_vals = [x[connection[0]], x[connection[1]]]
        y_vals = [y[connection[0]], y[connection[1]]]
        z_vals = [z[connection[0]], z[connection[1]]]
        fig.add_trace(go.Scatter3d(x=x_vals, y=y_vals, z=z_vals, mode='lines', line=dict(color='blue')))

    # Combine x, y, z values into a single list
    all_values = x + y + z

    # Find the minimum and maximum values
    min_value = min(all_values) - abs(min(all_values) * 0.1)
    max_value = max(all_values) + abs(max(all_values) * 0.1)

    # Update layout to set axis limits
    fig.update_layout(
        scene=dict(
            aspectmode='cube',
            xaxis=dict(title='X', range=[min_value, max_value]),
            yaxis=dict(title='Y', range=[min_value, max_value]),
            zaxis=dict(title='Z', range=[min_value, max_value])
        )
    )

    fig.show()

    return fig

epoch = 10
keypoints = [(1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12), (13, 14, 15),
             (16, 17, 18), (19, 20, 21), (22, 23, 24), (25, 26, 27),
             (28, 29, 30), (31, 32, 33), (34, 35, 36), (37, 38, 39),
             (40, 41, 42), (43, 44, 45), (46, 47, 48)]

figure = plot_3d_keypoints(keypoints, "mediapipe", epoch)

wandb.init(project="data-3d-test")
wandb.log({'Model Output: Morphed Keypoints': wandb.Plotly(figure), "epoch": epoch+1})
wandb.log({'Ground Truth: Dataset Keypoints': figure, "epoch": epoch+1})
wandb.log({'Model Input: Keypoints': figure, "epoch": epoch+1})

Hi @ofplarsen ,

We wanted to follow up with you regarding your support request as we have not heard back from you. Please let us know if we can be of further assistance or if your issue has been resolved.

Best Regards,
Weights & Biases

Sry for late response. The error is still being thrown, but the plots are being uploaded so it is not a breaking bug for me. I just catch the excepotion

Thanks for your update @ofplarsen. Does that mean you are still getting the exception when using the code we provided? If yes, can you share the debug-internal.log and debug.log for the affected run? These files are under your local folder wandb/run-_-/logs in the same directory where you’re running your code. These files will help us with more details about this error

Hi @ofplarsen, since we have not heard back from you we are going to close this request. If you would like to re-open the conversation, please let us know!