# AI-ML-Project-Embryo-Analysis-to-Improve-Success-Rate-of-IVF **This project is a recreation of STORK repository [Github Link to STORK](https://github.com/ih-lab/STORK) which is used for embryo classification.** ![-----------------------------------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)

:book: Table of Contents

Table of Contents 1.[About the Project](#ATP) 2.[Prerequisites](#Prerequisites) 3.[Dataset](#Dataset) 4.[Data_Pipeline](#Data_Pipeline) 5.[Methodology](#Methodology) 6.[Results and Discussion](#Results_and_Discussion) 7.[References](#References) 8.[Contributors](#Contributors) 9.[Steps To Follow](#Steps_To_Follow)

:pencil: About The Project

Infertility is defined as a clinical condition of inability to conceive or get pregnant after one year or longer of unprotected sex. IVF stands for In vitro fertilization. It is a type of assistive reproductive technology (ART) for infertility treatment and surrogacy. Surrogacy is an arrangement where another woman agrees to labour deliver for another person where pregnancy is medically impossible. Approximately 16% which is 1 in 6 couples in Canada experience infertility (UCLA Health, 2020). This number has doubled since the 1980’s. Apart from the emotional trauma a couple goes through during their journey of infertility they have to invest a lot of time and money into the IVF process.

The below figure explains the whole IVF process step by step. IVF involves many steps, and each cycle would take an average duration of 6 to 8 weeks. At first the individual would undergo an initial consultation and testing with an infertility specialist and would be prescribed medication for ovarian stimulation in which the ovary is stimulated to produce multiple healthy eggs. Then the doctor retrieves the eggs from the woman’s ovary. The retrieved eggs are fertilized with the sperm from the semen sample of a partner or a sperm donor in a culture medium in a laboratory. The fertilized egg undergoes embryo culture where the fertilized eggs are allowed to grow in an artificial medium (incubator) under supervision. After 3 – 5 days once the embryo reaches the blastocyst stage, the best embryos are selected by the embryologists based on the morphological attributes and are transferred into the woman’s uterus. After two weeks of embryo transfer the couple undergoes for a pregnancy test and the success of the IVF process is determined.

Standard morphological assessment of the embryo by the embryologist has always been the major tool for selecting the best embryo for transfer.One cycle of an IVF process takes 6 to 8 weeks. On an average 3 IVF cycles is found to be clinically effective. The average cost of one round of IVF is estimated to be $15000, with a success rate of less than 50% per embryo transfer.Manual assessment may result in human error based on their experience, intuition and expertise. Multiple viable blastocysts were transferred to increase the chances of pregnancy, but this would result in multiple pregnancies and gestational complications in the mothers and babies. Therefore, identifying the single best viable blastocyst is recommended which would reduce the number of cycles administered and eliminate multiple pregnancies and other related issues. Our project aims at building a supervised learning classification model to classify the embryo based on their quality into good or bad thereby eliminating the factor of human error and the need for multiple cycles.

![-----------------------------------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)

:fork_and_knife: Prerequisites

[![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/)
The following open source packages are used in this project: * Numpy * TensorFlow * Keras * dataset_utils * math * os * random * sys * matplotlib ![-----------------------------------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)

:open_file_folder: Dataset

Source : STORK Framework. Training Images : Good 42, Poor 42 Test Images: 14 This image dataset is publicly available and taken from the GitHub repository of STOCK, these images of human embryos were obtained from the Centre for Reproductive Medicine at Weill Cornell Medicine. There are total of 98 images. This image dataset was already in jpg format.

![-----------------------------------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)

:dart: Data Pipeline

![-----------------------------------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)

:scroll: Methodology

A Deep Neural Network (DNN) is used for embryo image analysis based on Google’s Inception-V1 architecture. The STORK repository had multiple pre-trained models out of which Inception V1 is best suitable for image classification. We have used STORK framework to predict blastocyst quality into good or poor. This study included a total of 98 blastocyst images, and the data is divided into two parts, 85% of the images (84) are used for training the model and the remaining 15% images (14) are used for testing the trained model.

![-----------------------------------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)

:mag: Results and Discussion

Deep neural network has high accuracy in classification of human embryo images. We have used pre trained Inception V1 model algorithm to train the images. The basic inception V1 has four parallel layers of 1X1 convolution, 3X3 convolution, 5X5 convolution and 3X3 max pooling. By employing our model, we could select the best viable embryo for transferring to the uterus. With the current IVF process, it is preferred to go for 3 cycles where 1 cycle costs up to $15,000 and 6-8 weeks. If our model could classify the embryos as good and poor there is a possibility of reducing the number of cycles in IVF. So, to classify the embryo, we leveraged a deep neural network to identify the quality of each embryo and we also used a stork framework, to find the quality of the embryo images. We have classified these embryo images into two classes,namely good and poor, by using the stork model. For testing data, our model gives an accuracy of 100% on a total of 14 images where all were predicted correctly. One of our limitations is that while training we got an accuracy of 100%, due to the limited number of datasets. Also, our model will go with the higher precision rate for true negative, where the poor embryo is predicted to be poor. We have developed a web page for the data product to Integrate the model, where an embryo image can be uploaded and the probability of that image being good or poor can be checked. The webpage can be used by a common person to check the quality (probability) of the uploaded embryo as good or poor.

![-----------------------------------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)

:books: References

1. A. Muhammad, H. Adnan, C. Jiho, and R. P. Kang, “Detecting Blastocyst Components by Artificial Intelligence for Human Embryological Analysis to Improve Success Rate of In Vitro Fertilization.” https://www.ncbi.nlm.nih.gov/pmc/articles/PMC8877842/ 2. A. Kirillova et al., “Should we transfer poor quality embryos?,” Fertil. Res. Pract., vol. 6, no. 1, pp. 1–7, 2020, doi: 10.1186/s40738-020-00072-5 3. P. F. Centre, “From consultation to embryo transfer.” https://www.pfcla.com/services/in-vitro-fertilization/overview 4. STORK GitHub https://github.com/ih-lab/STORK/tree/master/scripts ![---------------------------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)

:writing_hand: Contributors

:mortar_board: All participants in this project are post graduate students of the Data Analytics for Business course @ St. Clair College :girl: Anjana Padikkal Veetil
      Email: AP202@myscc.ca
      GitHub: @anjanapv
:woman_in_tuxedo: Nobin Ann Mathew
      Email: NM91@myscc.ca
      GitHub: @nobinmathew
:boy: Santosh Kumar Kantimahanti Lakshmi
      Email: SK602@myscc.ca
      GitHub: @santosh
:man_beard: Amal Mathew
      Email: AM252@myscc.ca
      GitHub: @amal

![-----------------------------------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)

:arrow_right: Steps To Follow

To run the algorithm please follow these steps:

1. Install the TensorFlow(version 1.15). Follow the instruction from here: https://www.tensorflow.org/install/

2. Pre-trained Models of CNN architectures should be downloaded from the "Pre-trained Models" part of https://github.com/wenwei202/terngrad/tree/master/slim#pre-trained-models and be located in your machine (e.g. AI-ML-Project-Embryo-Analysis-to-Improve-Success-Rate-of-IVF/scripts/slim/run/checkpoint). The files for pre-trained models should be available under the folder named "Checkpoint".

3. _NUM_CLASSES should be set as 2 ( as we are classifying the embryo into good or poor ) in embryo.py python file (this script is located in AI-ML-Project-Embryo-Analysis-to-Improve-Success-Rate-of-IVF/scripts/slim/datasets).

4. Run the convert.py (it is located in the "AI-ML-Project-Embryo-Analysis-to-Improve-Success-Rate-of-IVF/scripts" directory) to allocate the suitable percentage of images to train and validation sets. The convert.py needs three arguments: the address of images for training, the address of where the result will be located, and the percentage of validation images for the training step: ``` $ python convert.py ../Images/train process/ 0 ``` - Keep the percentage of validation images as 0 because we set 15% for validation inside the code. - It will save converted .tf files in the "process" directory.

5. The Inception-V1 architecture should be run on the Train images from the "AI-ML-Project-Embryo-Analysis-to-Improve-Success-Rate-of-IVF/scripts/slim" directory. First go to the following directory: AI-ML-Project-Embryo-Analysis-to-Improve-Success-Rate-of-IVF/scripts/slim. Then open load_inception_v1.sh located in "run/" directory and edit PRETRAINED_CHECKPOINT_DIR,TRAIN_DIR, and DATASET_DIR addresses. See the load_inception_v1.sh, for instance. Then, run the following command in shell script: ``` $ ./run/load_inception_v1.sh ``` - If your system supports linux commands run load_inception_v1.sh otherwise run the below python file. ``` PRETRAINED_CHECKPOINT_DIR=run/checkpoint TRAIN_DIR= /scripts/result #The directory where you want to save your trained models. DATASET_DIR=/scripts/process #The directory where processed.tf records are located. python train_image_classifier.py --train_dir=${TRAIN_DIR} --dataset_name=embryo --dataset_split_name=train --dataset_dir=${DATASET_DIR} --model_name=inception_v1 --checkpoint_path=${PRETRAINED_CHECKPOINT_DIR}/inception_v1.ckpt --checkpoint_exclude_scopes=InceptionV1/Logits --max_number_of_steps=5000 --batch_size=32 --learning_rate=0.01 --save_interval_secs=100 --save_summaries_secs=100 --log_every_n_steps=300 --optimizer=rmsprop --weight_decay=0.00004 --clone_on_cpu=True ```

6. The trained algorithms should be tested using test set images. In folder "AI-ML-Project-Embryo-Analysis-to-Improve-Success-Rate-of-IVF/scripts/slim", predict.py loads a trained model on provided test images. This code needs 5 arguments

:arrow_right: Steps To Follow

To quickly test if the embryo classification model is working, please follow these simplified steps:

1. **Install Conda:** If you don't have Conda installed, follow the instructions for your operating system from the official Conda website: [https://docs.conda.io/en/latest/miniconda.html](https://docs.conda.io/en/latest/miniconda.html)

2. **Create and Activate Conda Environment:** Open your terminal or Anaconda prompt and run the following commands to create a new conda environment named `embryo-env` with Python 3.7 and activate it:

conda create -n embryo-env python=3.7
conda init  # Initialize conda for your shell (you might need to restart your terminal after this)
conda activate embryo-env

3. **Install Dependencies:** Navigate to the root directory of the project (where `requirements.txt` is located) in your terminal and install the required Python packages using pip:

pip install -r requirements.txt

4. **Change Directory to `slim`:** Navigate to the `slim` directory within the `ivf/scripts` folder:

cd ivf/scripts/slim

5. **Run the Test Script:** Execute the `tst.py` script to test the model with a sample image. This script is designed for a quick check to see if the model is functioning:

python tst.py

6. **Test with Different Images (Optional):** To test the model with different embryo images, open the `tst.py` file in a text editor. Locate the line that calls the `predict_image_label` function. It should look something like this:

from pred import predict_image_label
print("**************",predict_image_label("result","../../Images/test/good_23765483_-15_3AA.jpg","v1",),"**************")

Modify the image path within the `predict_image_label` function call to point to a different embryo image you want to test. Ensure the path is correct relative to the `slim` directory. For example, to test another image in the `Images/test` directory, you would change the path accordingly. Save the `tst.py` file after making changes and run `python tst.py` again.

7. **Understand the Output:** The `tst.py` script will print output to the console. The output is designed to show the prediction result for the image you tested. It will likely display probabilities or a classification (e.g., "good" or "poor") indicating the model's assessment of the embryo quality for the given image. Examine the printed output to verify if the model is providing predictions.



✤ This was the final project for the course B016 - Data Analytics for Business(May 2021), at
St. Clair College