0
$\begingroup$

I'm trying to implement a multi-label image classification from a CT scan data set. The goal of the work is to find out which CT scan image has eleven of the most common fractures if it is fractured. The data set contains 10699 images. I've tried with inception v3, alexnet, vgg16. vgg16 showed some promise after augmentation, but not too much great. I want to minimize the difference between training loss and validation loss while maximizing the F-beta score. I'm a beginner, so if anyone could tell me if where I'm doing wrong, I'd be very grateful. I think it's happening because my data set is too imbalanced. So I tried augmentation but to no avail. Below is the code of vgg16 model:

train = pd.read_csv('final.csv')
SIZE=256
train_image = []
for i in tqdm(range(train.shape[0])):
    img = image.load_img('/home/jupyter/Train-Data/'+train['ID'][i],target_size=(SIZE,SIZE,3))
    img = image.img_to_array(img)
    img = img/255.0
    train_image.append(img)

X = np.array(train_image)

y = np.array(train.drop(['ID', 'Classification'],axis=1))


def load_dataset():
  
    trainX, testX, trainY, testY = train_test_split(X, y, test_size=0.3, random_state=1)
    return trainX, trainY, testX, testY

def define_model(in_shape=(SIZE, SIZE, 3), out_shape=11):
    
    model = VGG16(include_top=False, input_shape=in_shape)
   
    for layer in model.layers:
        layer.trainable = False
   
    model.get_layer('block5_conv1').trainable = True
    model.get_layer('block5_conv2').trainable = True
    model.get_layer('block5_conv3').trainable = True
    model.get_layer('block5_pool').trainable = True
   
    flat1 = Flatten()(model.layers[-1].output)
    class1 = Dense(128, activation='relu', kernel_initializer='he_uniform')(flat1)
    output = Dense(out_shape, activation='sigmoid')(class1)
    
    model = Model(inputs=model.inputs, outputs=output)
   
    opt = SGD(lr=0.01, momentum=0.9)
    model.compile(optimizer=opt, loss='binary_crossentropy', metrics=[fbeta])
    return model
    

trainX, trainY, testX, testY = load_dataset()
train_datagen = ImageDataGenerator(rescale=1.0/255.0, horizontal_flip=True, vertical_flip=True, rotation_range=90)
test_datagen = ImageDataGenerator(rescale=1.0/255.0)

train_datagen.mean = [123.68, 116.779, 103.939]
test_datagen.mean = [123.68, 116.779, 103.939]

train_it = train_datagen.flow(trainX, trainY, batch_size=128)
test_it = test_datagen.flow(testX, testY, batch_size=128)

model = define_model()
model.summary()

history = model.fit_generator(train_it, steps_per_epoch=len(train_it), validation_data=test_it, validation_steps=len(test_it), epochs=20, verbose=1)

Alexnet Graph: Alexnet summary

Inception v3 Graph: Inception v3 summary

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.