2525
2626class lineage_population_model ():
2727 def __init__ (self , device = "cpu" ):
28-
28+ """Estimate lineage populations of C. elegans embroys from videos/photos and plotting predictions.
29+
30+ Args:
31+ device (str, optional): set to "cuda", runs operations on gpu and set to "cpu", runs operations on cpu. Defaults to "cpu".
32+ """
2933 self .device = device
3034 self .model = models .resnet18 (pretrained = True )
3135 self .model .fc = nn .Linear (512 , 7 ) ## resize last layer
@@ -57,25 +61,20 @@ def __init__(self, device = "cpu"):
5761 ])
5862
5963 def predict (self , image_path ):
64+ """Loads an image from image_path and converts it to grayscale,
65+ then passes it though the model and returns a dictionary
66+ with the scaled output (see self.scaler)
6067
61- """
6268 reference{
6369 https://github.com/DevoLearn/devolearn#predicting-populations-of-cells-within-the-c-elegans-embryo
64- }
65- input{
66- image path <str>
6770 }
6871
69- output{
70- dictionary containing the cell population values <dict>
71- }
72-
73- Loads an image from image_path and converts it to grayscale,
74- then passes it though the model and returns a dictionary
75- with the scaled output (see self.scaler)
72+ Args:
73+ image_path (str): path to image.
7674
75+ Returns:
76+ dict: dictionary containing the cell population values
7777 """
78-
7978 image = cv2 .imread (image_path , 0 )
8079 image = cv2 .cvtColor (image , cv2 .COLOR_GRAY2RGB )
8180 tensor = self .transforms (image ).unsqueeze (0 ).to (self .device )
@@ -96,29 +95,23 @@ def predict(self, image_path):
9695 return pred_dict
9796
9897 def predict_from_video (self , video_path , csv_name = "foo.csv" , save_csv = False , ignore_first_n_frames = 0 , ignore_last_n_frames = 0 , notebook_mode = False ):
99-
100- """
101- inputs{
102- video path <str> = path to video file
103- csv_name <str> = filename to be used to save the predictions
104- save_csv <bool> = set to True if you want to save the predictions into a CSV files
105- ignore_first_n_frames <int> = number of frames to drop in the start of the video
106- ignore_last_n_frames <int> = number of frames to drop in the end of the video
107- notebook_mode <bool> = toogle between script(False) and notebook(True), for better user interface
108- }
109-
110-
111- output{
112- DataFrame containing all the preds with the corresponding column name <pandas.DataFrame>
113- }
114-
115- Splits a video from video_path into frames and passes the
98+ """Splits a video from video_path into frames and passes the
11699 frames through the model for predictions. Saves all the predictions
117100 into a pandas.DataFrame which can be optionally saved as a CSV file.
118101
119102 The model was trained to make predictions upto the
120- stage where the population of "A" lineage is 250
121-
103+ stage where the population of "A" lineage is 250
104+
105+ Args:
106+ video_path (str): path to video file
107+ csv_name (str, optional): filename to be used to save the predictions. Defaults to "foo.csv".
108+ save_csv (bool, optional): set to True if you want to save the predictions into a CSV files. Defaults to False.
109+ ignore_first_n_frames (int, optional): number of frames to drop in the start of the video. Defaults to 0.
110+ ignore_last_n_frames (int, optional): number of frames to drop in the end of the video. Defaults to 0.
111+ notebook_mode (bool, optional): toogle between script(False) and notebook(True), for better user interface. Defaults to False.
112+
113+ Returns:
114+ pandas.DataFrame : DataFrame containing all the preds with the corresponding column name
122115 """
123116 A_population_upper_limit = 250
124117
@@ -180,23 +173,18 @@ def predict_from_video(self, video_path, csv_name = "foo.csv", save_csv = False
180173
181174
182175 def create_population_plot_from_video (self , video_path , save_plot = False , plot_name = "plot.png" , ignore_first_n_frames = 0 , ignore_last_n_frames = 0 , notebook_mode = False ):
183-
184- """
185- inputs{
186- video_path <str> = path to video file
187- save_plot <bool> = set to True to save the plot as an image file
188- plot_name <str> = filename of the plot image to be saved
189- ignore_first_n_frames <int> = number of frames to drop in the start of the video
190- ignore_last_n_frames <int> = number of frames to drop in the end of the video
191- notebook_mode <bool> = toogle between script(False) and notebook(True), for better user interface
192- }
193-
194- outputs{
195- plot object which can be customized further <matplotlib.pyplot>
196- }
197-
198- plots all the predictions from a video into a matplotlib.pyplot
199-
176+ """Plots all the predictions from a video into a matplotlib.pyplot
177+
178+ Args:
179+ video_path ([type]): path to video file
180+ save_plot (bool, optional): set to True to save the plot as an image file. Defaults to False.
181+ plot_name (str, optional): filename of the plot image to be saved. Defaults to "plot.png".
182+ ignore_first_n_frames (int, optional): number of frames to drop in the start of the video. Defaults to 0.
183+ ignore_last_n_frames (int, optional): number of frames to drop in the end of the video. Defaults to 0.
184+ notebook_mode (bool, optional): toogle between script(False) and notebook(True), for better user interface. Defaults to False.
185+
186+ Returns:
187+ matplotlib.pyplot : plot object which can be customized further
200188 """
201189 df = self .predict_from_video (video_path , ignore_first_n_frames = ignore_first_n_frames , ignore_last_n_frames = ignore_last_n_frames , notebook_mode = notebook_mode )
202190
0 commit comments