Kaggle competition: RANZCR CLiP - Catheter and Line Position Challenge
<SOS> metric: MCAUC Kaggle data source: ranzcr-clip-catheter-and-line-position-challenge<load_from_csv>
train = pd.read_csv("/kaggle/input/Kannada-MNIST/train.csv")
 train.head()<load_from_csv>
AUTO = tf.data.experimental.AUTOTUNE
DIM = 600
IMAGE_SIZE=[DIM,DIM]
BATCH_SIZE = 8
DATA_PATH = ".. /input/ranzcr-clip-catheter-line-classification/"
OUTPUT_PATH = "./"
test = pd.read_csv("/kaggle/input/Kannada-MNIST/test.csv")
 test.head()<load_from_csv>
!pip install.. /input/kerasapplications/keras-applications-master/
package_path = '.. /input/efficientnetmaster/efficientnet-master/'
sys.path.append(package_path)
sample_submission = pd.read_csv("/kaggle/input/Kannada-MNIST/sample_submission.csv")
 sample_submission.head()<data_type_conversions>
TEST_FILENAMES = tf.io.gfile.glob('.. /input/ranzcr-clip-catheter-line-classification/test_tfrecords/*.tfrec')
 print(TEST_FILENAMES )
images = train.iloc[:, 1:].values.reshape(train.shape[0],28, 28 ).astype('float32')/255.0
images=images.reshape(train.shape[0],28, 28,1)
 images_test = test.iloc[:, 1:].values.reshape(test.shape[0],28, 28 ).astype('float32')/255.0
images_test=images_test.reshape(test.shape[0],28, 28,1)
 label = train.iloc[:,0].astype('int' ).values
ids_test = test.iloc[:,0].values
plt.imshow(images[0].reshape(28,28),cmap='gray')
 plt.title(label[0] )<split>
def decode_image(image_data):
image = tf.image.decode_jpeg(image_data, channels=3)
 image = tf.cast(image, tf.float32)/ 255.0
image = tf.image.resize(image, [DIM, DIM])
 image = tf.reshape(image, [*IMAGE_SIZE, 3])
 return image
def read_unlabeled_tfrecord(example):
UNLABELED_TFREC_FORMAT = {
'image': tf.io.FixedLenFeature([], tf.string),
'StudyInstanceUID': tf.io.FixedLenFeature([], tf.string)
 }
example = tf.io.parse_single_example(example, UNLABELED_TFREC_FORMAT)
 image = decode_image(example['image'])
 idnum = example['StudyInstanceUID']
return image, idnum
def load_dataset(filenames, labeled = True, ordered = False):
ignore_order = tf.data.Options()
if not ordered:
ignore_order.experimental_deterministic = False
dataset = tf.data.TFRecordDataset(filenames, num_parallel_reads = AUTO)
 dataset = dataset.with_options(ignore_order)
 dataset = dataset.map(read_unlabeled_tfrecord, num_parallel_calls = AUTO)
 return dataset
def get_test_dataset(ordered=False):
dataset = load_dataset(TEST_FILENAMES, labeled=False, ordered=ordered)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.prefetch(AUTO)
 return dataset
def count_data_items(filenames):
n = [int(re.compile(r"-([0-9]*)\." ).search(filename ).group(1)) for filename in filenames]
return np.sum(n)
 NUM_TEST_IMAGES = count_data_items(TEST_FILENAMES )
images_train, images_validation,label_train,label_validation = train_test_split(images,label,test_size=0.1 )<categorify>
models1=[]
for filename in glob.glob('.. /input/eff7trained/*best.h5'):
model = tf.keras.models.load_model(filename, custom_objects = None)
 models1.append(model)
label_train = to_categorical(label_train )<categorify>
test_ds = get_test_dataset(ordered=True)
 test_images_ds = test_ds.map(lambda image, idnum: image)
 labels = ['ETT - Abnormal', 'ETT - Borderline',
'ETT - Normal', 'NGT - Abnormal', 'NGT - Borderline',
'NGT - Incompletely Imaged', 'NGT - Normal', 'CVC - Abnormal',
'CVC - Borderline', 'CVC - Normal', 'Swan Ganz Catheter Present']
mean =(models1[0].predict(test_images_ds)
 +models1[1].predict(test_images_ds)
 +models1[2].predict(test_images_ds)
 +models1[3].predict(test_images_ds)
 +models1[4].predict(test_images_ds)) /5.0
label_validation = to_categorical(label_validation )<import_modules>
test_ids_ds = test_ds.map(lambda image, idnum: idnum ).unbatch()
test_ids = next(iter(test_ids_ds.batch(NUM_TEST_IMAGES)) ).numpy().astype('U' )
from tensorflow.python.keras.applications.vgg16 import VGG16
from tensorflow.keras.layers import Dense,Conv2D, MaxPooling2D, Flatten,BatchNormalization,Dropout
from tensorflow.keras.models import Sequential<choose_model_class>
submission = pd.DataFrame(mean, columns = labels)
 submission.insert(0, "StudyInstanceUID", test_ids, False)
 submission['StudyInstanceUID'] = submission['StudyInstanceUID'].apply(lambda x: x.rstrip(".jpg"))
submission.to_csv('submission.csv', index=False )
<choose_model_class><EOS> 
print("Done" )