Kaggle competition: Cassava Leaf Disease Classification
new_data=new_data.drop('genres',axis=1 )<find_best_params>
test_df = pd.read_csv('.. /input/cassava-leaf-disease-classification/sample_submission.csv')
 print(test_df)
 AUTOTUNE = tf.data.experimental.AUTOTUNE
GCS_PATH = '.. /input/cassava-leaf-disease-classification'
BATCH_SIZE = 16*8
IMAGE_SIZE = [512,512]
CLASSES = ["1", "2", "3", "4", "5"]
def dataset_sizes(filenames):
n = [int(re.compile(r"-([0-9]*)\." ).search(filename ).group(1)) for filename in filenames]
return(np.sum(n))
TEST_FILENAMES = tf.io.gfile.glob(GCS_PATH+"/test_tfrecords/ld_test*.tfrec")
 NUM_TEST_IMAGES = dataset_sizes(TEST_FILENAMES )
country=new_data['production_countries'].str.findall(r'[A-Z]{2,5}')
<feature_engineering>
def to_float32(image, label):
return tf.cast(image, tf.float32), label
def decode_img(img):
img = tf.io.decode_jpeg(img, channels = 3)
 img = tf.cast(img, tf.float32)/255.0
img = tf.reshape(img, [*IMAGE_SIZE, 3])
 return img
def read_tfrecord(example, labeled):
if labeled:
TFREC_FORMAT = {
"image": tf.io.FixedLenFeature([], tf.string),
"target": tf.io.FixedLenFeature([], tf.int64)
 }
else:
TFREC_FORMAT = {
"image": tf.io.FixedLenFeature([], tf.string),
"image_name": tf.io.FixedLenFeature([], tf.string)
 }
example = tf.io.parse_single_example(example, TFREC_FORMAT)
 img = decode_img(example["image"])
 if labeled:
label = tf.cast(example["target"], tf.int32)
 return(img, label)
 else:
idNum = example["image_name"]
return(img, 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 = AUTOTUNE)
 dataset.with_options(ignore_order)
 dataset = dataset.map(partial(read_tfrecord, labeled = labeled), num_parallel_calls = AUTOTUNE)
 return dataset
def get_test_data(ordered = False):
dataset = load_dataset(filenames = TEST_FILENAMES, labeled = False, ordered = ordered)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.prefetch(AUTOTUNE)
 return dataset
new_data['production_countries']=country 
<feature_engineering>
test_ds = get_test_data(ordered=True)
 test_ds = test_ds.map(to_float32)
 testing_dataset = get_test_data()
testing_dataset = testing_dataset.unbatch().batch(1)
 print('Computing predictions...')
 test_images_ds = testing_dataset
test_images_ds = test_ds.map(lambda image, idnum: image)
 prob1 = model_15.predict(test_images_ds)
 prob2 = model_17.predict(test_images_ds)
 prob6 = model_21.predict(test_images_ds)
 prob10 = model_28_1.predict(test_images_ds)
 probabilities = 0.25*(prob1+prob2+prob6+prob10)
 predictions = np.argmax(probabilities, axis = -1)
 print(predictions )
<drop_column><EOS> 
print('Generating submission.csv file...')
 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')
 np.savetxt('submission.csv', np.rec.fromarrays([test_ids, predictions]), fmt=['%s', '%d'], delimiter=',', header='image_id,label', comments='' )