ZumoLabs / zpy

Synthetic data for computer vision. An open source toolkit using Blender and Python.
GNU General Public License v3.0
302 stars 35 forks source link

Attribute Error on zpy.objects.segment #148

Closed franferraz98 closed 3 years ago

franferraz98 commented 3 years ago

Greetings,

I've just succeeded on installing Blender 2.80 with the latest version of zpy-zumo on my Ubuntu 20.04 and Python 3.8, and I was about to execute your code for the Suzanne 1 tutorial. When I did, after creating the Suzanne object and adding a material to it, this error popped up.

2021-10-22 16:31:18,938: INFO blender.py] Setting random seed to 0 Traceback (most recent call last): File "/home/deeplearning/Projects/Blender/suzanne.blend/run", line 76, in File "/home/deeplearning/Projects/Blender/suzanne.blend/run", line 19, in run File "/home/deeplearning/.local/lib/python3.8/site-packages/zpy/objects.py", line 301, in segment populate_vertex_colors(obj, zpy.color.frgb_to_frgba(color), seg_type) File "/home/deeplearning/.local/lib/python3.8/site-packages/zpy/objects.py", line 334, in populate_vertex_colors if len(obj.data.sculpt_vertex_colors): AttributeError: 'Mesh' object has no attribute 'sculpt_vertex_colors' Error: Python script failed, check the message in the system console

I'd say this is due to the program being unable to recognize the material of the object, but being both new to Blender and to Zumo I can't really tell. My code here (it's the same as yours):

""" Suzanne Tutorial Sim. """

import bpy import zpy

def run(num_images: int = 5):

# Random seed results in unique behavior
zpy.blender.set_seed()

# Create the saver object
saver = zpy.saver_image.ImageSaver(description="Suzannes from a camera view")

# Add the Suzanne category
suzanne_seg_color = zpy.color.random_color(output_style="frgb")
saver.add_category(name="Suzanne", color=suzanne_seg_color)

# Segment Suzzanne (make sure a material exists for the object!)
zpy.objects.segment("Suzanne", color=suzanne_seg_color)

# Run the sim.
for step_idx in zpy.blender.step(num_steps=num_images):

    # Name for each of the output images
    rgb_image_name = zpy.files.make_rgb_image_name(step_idx)
    iseg_image_name = zpy.files.make_iseg_image_name(step_idx)

    # Render image
    zpy.render.render(
        rgb_path=saver.output_dir / rgb_image_name,
        iseg_path=saver.output_dir / iseg_image_name,
        width=640,
        height=480,
    )

    # Add images to saver
    saver.add_image(
        name=rgb_image_name,
        style="default",
        output_path=saver.output_dir / rgb_image_name,
        frame=step_idx,
        width=640,
        height=480,
    )
    saver.add_image(
        name=iseg_image_name,
        style="segmentation",
        output_path=saver.output_dir / iseg_image_name,
        frame=step_idx,
        width=640,
        height=480,
    )

    # Add annotation to segmentation image
    saver.add_annotation(
        image=rgb_image_name,
        seg_image=iseg_image_name,
        seg_color=suzanne_seg_color,
        category="Suzanne",
    )

# Write out annotations
saver.output_annotated_images()
saver.output_meta_analysis()

# ZUMO Annotations
zpy.output_zumo.OutputZUMO(saver).output_annotations()

# COCO Annotations
zpy.output_coco.OutputCOCO(saver).output_annotations()

if name == "main":

# Run the sim
run()

Maybe this is a conflict with the Blender version? Should I try installing 2.93?

Thanks in advance, your project seems very promising. I never opened a GitHub issue before, so sorry if the format isn't proper.

hu-po commented 3 years ago

Thanks for the detailed response! I think your intuition is correct here, this is likely a Blender 2.80 issue. The .sculpt_vertex_colors property was added in 2.90 when they refactored that part of the Blender Python API. Easiest fix for you is to update to the latest Blender version, but if you have other reasons for not doing so you can create a fork of zpy and change that line.

franferraz98 commented 3 years ago

Indeed it was an issue with the Blender version, installing Blender 2.93 solved it. Thanks Hugo!