Skip to content

Mind Crusaders - Medical Image Processing #12

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Binary file added Benchmarking.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Model pb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions Pneumonia Prediction/Pneumonia Prediction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <CL/sycl.hpp>
#include <opencv2/opencv.hpp>
#include <cmath>
#include <iostream>
#include "dnnl.hpp"

using namespace cl::sycl;

std::vector<cv::Mat> loadImages(const std::vector<std::string>& imagePaths) {
std::vector<cv::Mat> images;
for (const auto& imagePath : imagePaths) {
cv::Mat image = cv::imread(imagePath);
cv::resize(image, image, cv::Size(120, 120));
images.push_back(image);
}
return images;
}

int main() {
std::vector<std::string> trainingImagePaths = {
"/train/PNEUMONIA/person1000_bacteria_2931.jpeg",
"/train/NORMAL/IM-0115-0001.jpeg"
};

std::vector<cv::Mat> trainingImages = loadImages(trainingImagePaths);

std::vector<sycl::float3> trainingImageData;
for (const auto& image : trainingImages) {
for (int row = 0; row < image.rows; ++row) {
for (int col = 0; col < image.cols; ++col) {
cv::Vec3b pixel = image.at<cv::Vec3b>(row, col);
sycl::float3 normalizedPixel(
static_cast<float>(pixel[0]) / 255.0f,
static_cast<float>(pixel[1]) / 255.0f,
static_cast<float>(pixel[2]) / 255.0f
);
trainingImageData.push_back(normalizedPixel);
}
}
}

std::vector<int> labels = { 1, 0 };

auto deviceSelector = sycl::default_selector{};
auto queue = sycl::queue{ deviceSelector };

sycl::buffer<sycl::float3, 1> trainingDataBuffer(trainingImageData.data(), sycl::range(trainingImageData.size()));
sycl::buffer<int, 1> labelsBuffer(labels.data(), sycl::range(labels.size()));
sycl::buffer<float, 1> predictionsBuffer(sycl::range(labels.size()));

dnnl::convolution_forward convolution;

auto predictionsHost = predictionsBuffer.get_access<sycl::access::mode::read>();

for (size_t i = 0; i < labels.size(); ++i) {
std::cout << "The probability of pneumonia is: " << predictionsHost[i] << std::endl;
}
}
25 changes: 25 additions & 0 deletions Pneumonia Prediction/Pneumonia Prediction.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33815.320
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Pneumonia Prediction", "Pneumonia Prediction.vcxproj", "{0974D031-4449-48EA-838B-1D513F20811B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0974D031-4449-48EA-838B-1D513F20811B}.Debug|x64.ActiveCfg = Debug|x64
{0974D031-4449-48EA-838B-1D513F20811B}.Debug|x64.Build.0 = Debug|x64
{0974D031-4449-48EA-838B-1D513F20811B}.Release|x64.ActiveCfg = Release|x64
{0974D031-4449-48EA-838B-1D513F20811B}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9738CD98-C428-4F55-B17A-7D43A31AE021}
EndGlobalSection
EndGlobal
86 changes: 86 additions & 0 deletions Pneumonia Prediction/Pneumonia Prediction.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{0974d031-4449-48ea-838b-1d513f20811b}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Pneumonia_Prediction</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>Intel(R) oneAPI DPC++ Compiler 2023</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>Intel(R) oneAPI DPC++ Compiler 2023</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader></PrecompiledHeader>
<PrecompiledHeaderFile></PrecompiledHeaderFile>
<SYCLWarningLevel>Level3</SYCLWarningLevel>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader></PrecompiledHeader>
<PrecompiledHeaderFile></PrecompiledHeaderFile>
<SYCLWarningLevel>Level3</SYCLWarningLevel>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Pneumonia Prediction.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
22 changes: 22 additions & 0 deletions Pneumonia Prediction/Pneumonia Prediction.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="$projectname$.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions Pneumonia Prediction/Pneumonia Prediction.vcxproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
# intel-oneAPI

#### Team Name -
#### Problem Statement -
#### Team Leader Email -
#### Team Name - Mind Crusaders
#### Problem Statement - Medical Image Processing
#### Team Leader Email - [email protected]

## A Brief of the Prototype:
This section must include UML Daigrms and prototype description
This project demonstrates the quantization of a Medical Image processing using Intel OpenVINO. Quantization is a compression technique that reduces the memory footprint and computation requirements of a neural network model while maintaining its accuracy. The quantized model can be deployed on resource-constrained devices without compromising performance.

## Tech Stack:
List Down all technologies used to Build the prototype **Clearly mentioning Intel® AI Analytics Toolkits, it's libraries and the SYCL/DCP++ Libraries used**
- Intel OpenVINO toolkit
- Python 3.7 or above
- OpenVINO Python API
- OpenCV
- NumPy
- PIL

## Step-by-Step Code Execution Instructions:
This Section must contain set of instructions required to clone and run the prototype, so that it can be tested and deeply analysed
Step 1: Set up the Environment

Ensure you have installed the required dependencies and libraries, including Intel oneAPI toolkits and OpenVINO.
Make sure you have the appropriate Python environment set up with the necessary packages.
Step 2: Prepare the Model

Place your model files (model.xml and model.bin) in the "./model" directory.
Confirm that the model files exist in the specified directory.
Step 3: Run the Code

Copy the provided code into a Python file (e.g., medical_image_processing.py).
Open a terminal or command prompt and navigate to the directory where the Python file is located.
Step 4: Execute the Code

Run the Python script using the following command:
python model.py

## What I Learned:
Write about the biggest learning you had while developing the prototype
## What we Learnt:
we have learned the following key points:

Model Export: The code demonstrates how to export a trained model for deployment using Intel's OpenVINO toolkit. It loads the model from the specified directory, consisting of the model files (model.xml and model.bin), and utilizes the IECore class to read the network and its weights.

Inference Engine: The Intel IECore module is used to load the network onto the CPU device for inference. It provides a unified API to work with different deep learning frameworks and optimizes the execution of the network.

Model Update and Export: After loading the network, the code executes the model on the CPU device to perform network inference. It then exports the updated model, saving it as "updated_model.xml" in the same directory.
Binary file added mind_crusaders(final).pptx
Binary file not shown.