Closed evangeline-corcoran closed 10 months ago
Happy to look in to this - it sounds like a should be easy to solve. Could you send me an example mask so I can test the fix?
Thanks I've sent you an example empty mask
Addressing this in IFenton-37-BugFix
I can now successfully automatically create pixelflow 'features' objects for multiple files even if some mask files contain 0 labels, however attempting to also output .csv files with the features information as part of a loop over multiple files as below:
for file in X:
image = imread(file) #load whole pod image
pod_name = re.split("[/.]", file)[9] #save pod name for outputs
mask = np.load('/bask/homes/l/lwcf1795/vjgo8416-scivision/plant-phenotyping/3D_seed_biodiversity_data_200723/first and second rep/' + pod_name + '_pred.npy') #load whole pod label for metrics calculations
features = pixelflow(
mask,
image,
#custom=(custom_func,),
) #create table with metrics for each seed
features_csv = features.to_csv('/bask/homes/l/lwcf1795/vjgo8416-scivision/plant-phenotyping/3D_seed_biodiversity_data_200723/first and second rep/' + pod_name + '.csv',
header=True, index=False) #save metrics for all seeds in a pod to csv
Now gives the following error for files in the list with empty masks
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[6], line 14
8 mask = np.load('/bask/homes/l/lwcf1795/vjgo8416-scivision/plant-phenotyping/3D_seed_biodiversity_data_200723/first and second rep/' + pod_name + '_pred.npy') #load whole pod label for metrics calculations
9 features = pixelflow(
10 mask,
11 image,
12 #custom=(custom_func,),
13 ) #create table with metrics for each seed
---> 14 features_csv = features.to_csv('/bask/homes/l/lwcf1795/vjgo8416-scivision/plant-phenotyping/3D_seed_biodiversity_data_200723/first and second rep/' + pod_name + '.csv',
15 header=True, index=False) #save metrics for all seeds in a pod to csv
AttributeError: 'NoneType' object has no attribute 'to_csv'
Adding if features is not None
to the for loop before attempting to output a csv of the features table as shown below prevents this problem
for file in X:
image = imread(file) #load whole pod image
pod_name = re.split("[/.]", file)[9] #save pod name for outputs
image = normalize(image, 1,99.8, axis=axis_norm) #normalize image. NOTE: normalizer MUST be defined in step 3 and supplied here for prediction to function as expected
mask = np.load('/bask/homes/l/lwcf1795/vjgo8416-scivision/plant-phenotyping/3D_seed_biodiversity_data_200723/first and second rep/' + pod_name + '_pred.npy') #load whole pod label for metrics calculations
features = pixelflow(
mask,
image,
#custom=(custom_func,),
) #create table with metrics for each seed
if features is not None:
features_csv = features.to_csv('/bask/homes/l/lwcf1795/vjgo8416-scivision/plant-phenotyping/3D_seed_biodiversity_data_200723/first and second rep/' + pod_name + '.csv',
header=True, index=False) #if a pod has seeds, save metrics for all seeds in a pod to csv
@evangeline-corcoran Is this now resolved?
Yes I'm happy with this solution
Attempting to run pixelflow on a mask with no labels produces the following error:
I've verified that this was in fact a seed pod with 0 seeds, and therefore my seed detection model correctly produced a mask with 0 labels.
This is a problem mostly when running pixelflow over multiple images, as this error interrupts the automated loop.
The behaviour I would like to see is pixelflow skipping over a mask with 0 labels when going through a loop of files, or better yet flagging the empty mask with a print out i.e.
'mask_name.npy has 0 labels'