Closed ciaobladoo closed 8 months ago
Hi @ciaobladoo,
The Valis
object stores info about each image it's going to align in a Slide
object, and in the code I often refer to instances of these Slide
objects as slide_obj
. Errors like UnboundLocalError: local variable 'slide_obj'
might happen when there is an error in one of the steps, and the expected output to be used in the next step isn't produced, leading to the UnboundLocalError
. Based on the output above, it looks like the rigid registration may have failed after feature detection but before feature matching (hard to know why though), but this could be confirmed by checking the contents in the results directory, i.e. if the rigid_registration
folders wasn't created and populated then there was a problem during rigid registration. If rigid registration failed, you may want to check the images in the processed
folder to see if they look ok (i.e. not radically different, distorted, etc...)? Also, are you getting the same error in the same spot when not running on Databricks? Hopefully that helps a bit, but without more info it's difficult to pinpoint the exact cause behind the error.
Best, -Chandler
Thanks, Chandler. This helped me realize what went wrong. The issue is I have multiple pairs of images I need to register and I am specifying the same output directory. That is causing the issue. Maybe I should specify different output directories for each pair. Do you have any suggestions?
Glad that helped pinpoint the problem! One potential solution might be to set the "name" argument when you initialize the Valis
object, with a unique name (needs to be a string) for each pair of images. This should save the results for each pair in unique directory, because name
gets appended to the dst_dir
argument to create the folder where the results are saved. Hopefully that will work, but if not, let me know.
Best, -Chandler
Got it. I got the issue resolved.
Hi Chandler,
I seem to getting this error at random points when running Valis on Databricks. Could you advise what this error could mean?
Here are more detailed error messages:
Detecting features : 100%|██████████| 4/4 [00:22<00:00, 5.69s/image] /local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/valis/valtils.py:24: UserWarning: local variable 'slide_obj' referenced before assignment warnings.warn(warning_msg, warning_type) Traceback (most recent call last): File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/valis/registration.py", line 4203, in register rigid_registrar = self.rigid_register() File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/valis/registration.py", line 3058, in rigid_register rigid_registrar = serial_rigid.register_images(self.processed_dir, File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/valis/serial_rigid.py", line 1532, in register_images slide_obj = valis_obj.get_slide(img_obj.name) File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/valis/registration.py", line 2229, in get_slide return slide_obj UnboundLocalError: local variable 'slide_obj' referenced before assignment
JVM has been killed. If this was due to an error, then a new Python session will need to be started TypeError: list indices must be integers or slices, not NoneType
TypeError Traceback (most recent call last) File, line 15
13 registrar = registration.Valis(slide_src_dir, results_dst_dir, img_list=[os.path.join(slide_src_dir, row['folder_parent_name'],row['HE']), os.path.join(slide_src_dir, row['folder_parent_name'], row['CD3a'])])
14 rigid_registrar, non_rigid_registrar, error_df = registrar.register()
---> 15 registrar.warp_and_save_slides(os.path.join(registered_slide_dst_dir, str(idx)), crop="overlap")
16 shutil.copytree(os.path.join(registered_slide_dst_dir, str(idx)), os.path.join('/dbfs/mnt/gmb-dp-workspace/chfe/virtual_stainer/registered_slides', 'pair'+str(idx)))
17 registration.kill_jvm()
File /local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/valis/valtils.py:35, in deprecated_args..deco..wrapper(*args, kwargs)
32 @functools.wraps(f)
33 def wrapper(*args, *kwargs):
34 rename_kwargs(f.name, kwargs, aliases)
---> 35 return f(args, kwargs)
File /local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/valis/registration.py:4593, in Valis.warp_and_save_slides(self, dst_dir, level, non_rigid, crop, colormap, interp_method, tile_wh, compression, Q, pyramid) 4546 f"""Warp and save all slides 4547 4548 Each slide will be saved as an ome.tiff. The extension of each file will (...)
Thanks!
Chao