A physical examination and diagnostic imaging techniques including lung biopsies, ultrasounds, and chest X-rays are typically used to make the diagnosis of pneumonia infection, an infectious disease that has the potential to be life-threatening. The objective of this research is to categorize the stages of pneumonia through image processing methods. Before that, an ensemble model for diagnosing pneumonia infections is created utilizing the transfer learning algorithms ResNet50V2 and DenseNet201. The 5,857 images were taken from the PAUL MOONEY dataset for this research. The proposed ensemble averaging model recognizes lung infection appropriately and accurately. By applying a contour detection approach, the left and right chests are separated and the affected pixels from there to analyze the stage of pneumonia. It is very crucial to identify the stage for treatment purposes.