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

Header issues #31

Merged
merged 4 commits into from
Aug 10, 2023
Merged

Header issues #31

merged 4 commits into from
Aug 10, 2023

Conversation

LorenzLamm
Copy link
Collaborator

@LorenzLamm LorenzLamm commented Aug 10, 2023

Trying to fix some header issues arising from copying the header from the input tomogram.

Particularly, I'm only copying the labels from the original header, and the voxel size. Also, I changed the order of header declaration and setting the data, s.t. the automated header settings from setting the data will not be overwritten.

Also changed a small bug in reading the .csv file for extracting annotation patches.

@@ -84,7 +84,7 @@ def extract_patches(
pad_value = 2.0 # Currently still hard-coded because other values not
# compatible with training routine yet.
if coords_file is not None:
coords = get_csv_data(csv_path=coords_file)
coords = np.array(get_csv_data(csv_path=coords_file), dtype=int)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was read as strings sometimes, and thus did not extract patches properly.

if found_flag == 0:
print("No corrections folder found for patch", token)
if found_flag == 0:
print("No corrections folder found for patch", token)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This warning message was on the wrong level of the loop and thus given too often.

@@ -118,7 +118,7 @@ def load_data_for_inference(data_path: str, transforms: Callable, device: device
new_data = transforms(new_data)
new_data = new_data.unsqueeze(0) # Add batch dimension
new_data = new_data.to(device)
return new_data, tomogram.header
return new_data, tomogram.header, tomogram.voxel_size
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read additionally the tomogram's voxel size in order to store it properly later on.

@@ -334,7 +342,7 @@ def convert_dtype(tomogram: np.ndarray) -> np.ndarray:
if (
tomogram.min() >= np.finfo("float16").min
and tomogram.max() <= np.finfo("float16").max
):
) and np.allclose(tomogram, tomogram.astype("float16")):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing rounding to integers sometimes.

"my",
"mz",
]:
if attr not in ["nlabl", "label"]:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only copy these harmless header objects.
Not sure what exactly is valuable from the header, but since some stuff causes problems, better to be conservative I guess.


data = convert_dtype(data)
data = np.transpose(data, (2, 1, 0))
out_mrc.set_data(data)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the data is generating some header elements. Since these are data dependent, it's better to not have them overwritten with the above header loop.
Thus, I changed the order of data setting and header definition.

@LorenzLamm LorenzLamm marked this pull request as ready for review August 10, 2023 14:06
@LorenzLamm LorenzLamm merged commit 48e647d into main Aug 10, 2023
@LorenzLamm LorenzLamm deleted the header_issues branch August 10, 2023 14:07
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

Successfully merging this pull request may close these issues.

1 participant