Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Mansoura University

Faculty of Computers and Information science.


Information Technology Department.
Course: Health Information Management and Medical Data Analysis.
Code: [MED142]
Fourth Year (IT & BIO departments)

Homework 8:
Student Name
Student ID
Section 5
Dept. IT
Year 4th
Date 30/4/2023
Question1: Upload any medical dataset divided into three classes.

import tensorflow as tf
import numpy as np

# load your dataset, e.g. using pandas or numpy


# split your dataset into training, validation and test sets

# define the number of classes


num_classes = 3

# define the model architecture


model = tf.keras.Sequential([
tf.keras.layers.Dense(64, activation='relu', input_shape=(input_shape,)),
tf.keras.layers.Dense(32, activation='relu'),
tf.keras.layers.Dense(num_classes, activation='softmax')
])

# compile the model with the appropriate loss function, optimizer, and metrics
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

# train the model


history = model.fit(x_train, y_train, epochs=num_epochs, validation_data=(x_val, y_val))

# evaluate the model on the test set


test_loss, test_acc = model.evaluate(x_test, y_test)

# make predictions on new data using the trained model


predictions = model.predict(x_new_data)
Mansoura University
Faculty of Computers and Information science.
Information Technology Department.
Course: Health Information Management and Medical Data Analysis.
Code: [MED142]
Fourth Year (IT & BIO departments)

Question2: Apply CNN model on previous dataset for classification any unseen image.

from keras.models import Sequential


from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense

# load dataset
# preprocess images

# define CNN architecture


model = Sequential()
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(224, 224, 3)))
model.add(MaxPooling2D((2, 2)))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D((2, 2)))
model.add(Conv2D(128, (3, 3), activation='relu'))
model.add(MaxPooling2D((2, 2)))
model.add(Conv2D(128, (3, 3), activation='relu'))
model.add(MaxPooling2D((2, 2)))
model.add(Flatten())
model.add(Dense(512, activation='relu'))
model.add(Dense(1, activation='sigmoid'))

# compile the model


model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

# train the model


model.fit(train_images, train_labels, epochs=10, batch_size=32,
validation_data=(val_images, val_labels))

# evaluate the model


test_loss, test_acc = model.evaluate(test_images, test_labels)

# make predictions on new images


predictions = model.predict(new_images)

You might also like