image_output_3.png image_output_2.png image_output_1.png
from keras_preprocessing.image import ImageDataGenerator

import os

import os

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

train_img_csv = '../input/mura-dataset/MURA-v1.1/train_image_paths.csv'
train_images_paths = pd.read_csv(os.path.join(train_img_csv), dtype=str, header=None)
train_images_paths.columns = ['image_path']
train_images_paths['label'] = train_images_paths['image_path'].map(lambda x: '1' if 'positive' in x else '0')
train_images_paths['category'] = train_images_paths['image_path'].apply(lambda x: x.split('/')[2])
valid_img_csv = '../input/testdata/abdekho_valid.csv'
valid_images_paths = pd.read_csv(os.path.join(valid_img_csv), dtype=str, header=None)
valid_images_paths.columns = ['image_path']
valid_images_paths['label'] = valid_images_paths['image_path'].map(lambda x: '1' if 'positive' in x else '0')
valid_images_paths['category'] = valid_images_paths['image_path'].apply(lambda x: x.split('/')[2])

train_images_paths_XR_ELBOW = train_images_paths[train_images_paths['category'] == 'XR_ELBOW']
valid_images_paths_XR_ELBOW = valid_images_paths[valid_images_paths['category'] == 'XR_ELBOW']
train_images_paths_XR_FINGER = train_images_paths[train_images_paths['category'] == 'XR_FINGER']
valid_images_paths_XR_FINGER = valid_images_paths[valid_images_paths['category'] == 'XR_FINGER']
train_images_paths_XR_FOREARM = train_images_paths[train_images_paths['category'] == 'XR_FOREARM']
valid_images_paths_XR_FOREARM = valid_images_paths[valid_images_paths['category'] == 'XR_FOREARM']
train_images_paths_XR_HAND = train_images_paths[train_images_paths['category'] == 'XR_HAND']
valid_images_paths_XR_HAND = valid_images_paths[valid_images_paths['category'] == 'XR_HAND']
train_images_paths_XR_HUMERUS = train_images_paths[train_images_paths['category'] == 'XR_HUMERUS']
valid_images_paths_XR_HUMERUS = valid_images_paths[valid_images_paths['category'] == 'XR_HUMERUS']
train_images_paths_XR_SHOULDER = train_images_paths[train_images_paths['category'] == 'XR_SHOULDER']
valid_images_paths_XR_SHOULDER = valid_images_paths[valid_images_paths['category'] == 'XR_SHOULDER']
train_images_paths_XR_WRIST = train_images_paths[train_images_paths['category'] == 'XR_WRIST']
valid_images_paths_XR_WRIST = valid_images_paths[valid_images_paths['category'] == 'XR_WRIST']

datagen = ImageDataGenerator(rescale=1.0 / 255, rotation_range=10, width_shift_range=0.2, height_shift_range=0.2, horizontal_flip=True)
test_datagen = ImageDataGenerator(rescale=1.0 / 255, rotation_range=10)
images_path_dir = '../input/mura-dataset'
batchsize = 32
targetsize = (224, 224)
classmode = 'binary'
train_generator = datagen.flow_from_dataframe(dataframe=train_images_paths, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)
valid_generator = test_datagen.flow_from_dataframe(dataframe=valid_images_paths, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)
train_generator_XR_ELBOW = datagen.flow_from_dataframe(dataframe=train_images_paths_XR_ELBOW, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)
valid_generator_XR_ELBOW = test_datagen.flow_from_dataframe(dataframe=valid_images_paths_XR_ELBOW, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)
train_generator_XR_FINGER = datagen.flow_from_dataframe(dataframe=train_images_paths_XR_FINGER, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)
valid_generator_XR_FINGER = test_datagen.flow_from_dataframe(dataframe=valid_images_paths_XR_FINGER, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)
train_generator_XR_FOREARM = datagen.flow_from_dataframe(dataframe=train_images_paths_XR_FOREARM, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)
valid_generator_XR_FOREARM = test_datagen.flow_from_dataframe(dataframe=valid_images_paths_XR_FOREARM, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)
train_generator_XR_HAND = datagen.flow_from_dataframe(dataframe=train_images_paths_XR_HAND, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)
valid_generator_XR_HAND = test_datagen.flow_from_dataframe(dataframe=valid_images_paths_XR_HAND, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)
train_generator_XR_HUMERUS = datagen.flow_from_dataframe(dataframe=train_images_paths_XR_HUMERUS, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)
valid_generator_XR_HUMERUS = test_datagen.flow_from_dataframe(dataframe=valid_images_paths_XR_HUMERUS, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)
train_generator_XR_SHOULDER = datagen.flow_from_dataframe(dataframe=train_images_paths_XR_SHOULDER, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)
valid_generator_XR_SHOULDER = test_datagen.flow_from_dataframe(dataframe=valid_images_paths_XR_SHOULDER, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)
train_generator_XR_WRIST = datagen.flow_from_dataframe(dataframe=train_images_paths_XR_WRIST, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)
valid_generator_XR_WRIST = test_datagen.flow_from_dataframe(dataframe=valid_images_paths_XR_WRIST, directory=images_path_dir, x_col='image_path', y_col='label', target_size=targetsize, class_mode=classmode, batch_size=batchsize, suffle=True)