Functions that are used to markup up files with a learner

Imports

run_inferences[source]

run_inferences(learn:Learner, fnames:list, start:int=0, number_files=20)

run inferences over a list of fnames using learner

  • return a list of predictions

plot_inferences[source]

plot_inferences(preds:List, df:DataFrame, src_path:Path=PosixPath('.'), label=None, start:int=0, rows:int=4, cols:int=5)

Plot test images with auto markup labels

# def 
# def create_probs_df(fnames: List, ) -> DataFrame:
#     """
#     create a data frame of prob from a `fname` list
#      - param fnames: 
#      - return: `DataFrame`
#     """
#     list_filedata = [None] * len(fnames)
#     for i, fn in enumerate(fnames):
#         # img = PIL.Image.open(fn)
#         # img_w, img_h = img.size
#         list_filedata[i] = {'Name': fn.name, 'Background': '', 'Fluke Liver': '', 'Fluke Rumen': '', 'Other': '', 'Pstr': ''}
# 
#     df = pd.DataFrame(list_filedata)
#     df = df[['Name', 'Background', 'Fluke Liver', 'Fluke Rumen', 'Other', 'Pstr']]
#     df.set_index("Name", inplace=True)
#     return df

Predictions on tiles

get_region_props[source]

get_region_props(raw_pred:tensor, layer:int, min_conf:float=0.2, min_area:int=100)

return all the region properties of a prediction layer filtered by min confidence and min area

calc_probs[source]

calc_probs(raw_pred:tensor)

Calculate the probabilities from a raw prediction raw_pred by finding the average value of all the pixels within a region This assumes that there is only one cell in the image

  • raw_pred: the raw predictions from the learner
  • return: list of probabilities

preds_to_df[source]

preds_to_df(preds:List, col_headings:List, df:DataFrame)

add the predictions to the dataframe indexed by fname

  • preds: prediction list
  • col_headings: column headings
  • df: dataframe
  • return:

Predictions on whole images

find_prediction_blobs[source]

find_prediction_blobs(img, CONF=0.5, min_area=500, offset=0)

plot the prediction blobs on an image

draw_labels_on_image[source]

draw_labels_on_image(img, json, radius=40, offset=0)

Dataframe functions

add_cols_to_df[source]

add_cols_to_df(df:DataFrame, col_list:List)

To dataframe df add columns in col_list

  • df: dataframe to add columns to
  • col_list: list of columns to add
  • return: the df

Drawing functions

Draw text and graphics on an matplotlib image

bb_hw[source]

bb_hw(a)

draw_outline[source]

draw_outline(o, lw)

draw_rect[source]

draw_rect(ax, b)

draw_text[source]

draw_text(ax, xy, txt, sz=12, color='white', valign='top')

end