BlenderProc
BlenderProc copied to clipboard
[QUESTION]: Error with "Exception: There are more frames 2 than there are blocks of information 2 in the given list for key class_segmaps"
Describe the bug
This error is in the bproc.writer.write_hdf5() and there seems to be a mismatch in the length of data['colors'] and data['class_segmaps'] (class_segmaps is less than colors by 1). It does not happen on every loop but only some of them and it depends on number of camera poses been sampled. For lower number of camera poses, like 2 or 3, the error is rare but for higher number like 10+ , this error errors happens almost every time.
General Information
-
Which BlenderProc version are you using? 2.2.0
-
On which operating system are you? Ubuntu 20.04 LTS
-
Have you checked the issue tracker to see if a similar issue has been opened? Yes, couldn't find any other similar issue
-
Have you changed BlenderProc in any way besides the config file? If yes, are you sure that this change does not affect the problem you are having? Yes, the number of camera poses seems to have influence on it
To Reproduce Steps to reproduce the behavior:
- Provide the full command you used to run BlenderProc:
blenderproc run render_file.py - Provide the full python file, you used: Small snippet of my code relevant to this issue:
import bproc
import numpy as np
Label_mapping = bproc.utility.LabelIdMapping.from_dict({"forks": 1, "plates": 2})
for hdri_name in ["je_gray_park_4k.exr"]:
for hdri_rotation in [0, 180, 360]:
hdri_rotation *= np.pi/180
for _ in range(122):
bproc.init(compute_device_type="CUDA")
bproc.utility.reset_keyframes()
environment = bproc.loader.load_blend("./check_render.blend")
world_map_node = set_hdri(hdri_path)
world_map_node.inputs["Rotation"].default_value = (0, 0, hdri_rotation)
for pos, rot in location_sampler():
blender_obj.set_location(pos)
blender_obj.set_euler_rotation(rot)
blender_obj.set_cp("category_id", obj_id)
for i in range(10):
location_mtx = np.random.uniform([0, 0, 0.5], [125, 125, 3.5])
#rotation_mtx = bproc.camera.rotation_from_forward_vec(poi - location, inplane_rot=np.random.uniform(-0.7854, 0.7854))
rotation_mtx = np.random.uniform([(82*np.pi/180), -np.pi/9, 0], [(95*np.pi/180), np.pi/9, 2*np.pi])
cam2world_mtx = bproc.math.build_transformation_mat(location_mtx, rotation_mtx)
bproc.camera.add_camera_pose(cam2world_mtx)
data = bproc.renderer.render()
seg_data = bproc.renderer.render_segmap(map_by=["class", "instance", "name"])
bproc.writer.write_coco_annotations("./coco",
instance_segmaps=seg_data["instance_segmaps"],
instance_attribute_maps=seg_data["instance_attribute_maps"],
colors=data["colors"],
color_file_format="PNG",
label_mapping=Label_mapping)
data.update(seg_data)
bproc.writer.write_hdf5("./hdf5", data, append_to_existing_output=True)
del data
Screenshots
If applicable, add screenshots to help explain your problem.

Hey,
I would advise to move this into to scripts and call the inner loop starting with: bproc.init(compute_device_type="CUDA")
I assume the issue is with bproc.init() we try to clean up the blender world state but it is tricky, they don't offer a proper way of doing it, as blender was not designed to do this in a nice efficient way.
Maybe, if you insist on this loop you could try to load the default setting before the init every time, that should be a tiny bit faster than restarting blender every time: bpy.ops.wm.read_factory_settings(use_empty=True)
Maybe we should add that even to bproc.init() @cornerfarmer what do you say?
Best, Max
Resetting to factory settings seems to be good solution. But I noticed the problem only occurs with bproc.writer.write_hdf5("./hdf5", data, append_to_existing_output=True) and not with bproc.writer.write_coco_annotations(). So my temporary solution was to remove the bproc.writer.write_hdf5("./hdf5", data, append_to_existing_output=True), as all the data I need is present in coco annotations itself.
Hey @VishalBalaji321,
I agree with Max, the init call should only be done once, outside of the loop, however, there is at the moment no other way of performing the scene cleanup manually. Also I am not sure that this is really the source of your problem, it might also be a bug in the segmap renderer.
Could you please also share the check_render.blend file you are using or create a simple blend file which also results in the same error. This would make it easier for us to reproduce the bug.
We now split the init and the clean up this should be resolved.