Kaggle competition: Santander Customer Transaction Prediction
image_names = train["image_name"].values
image_names = image_names + ".jpg"
image_names<define_variables>
random_images = [np.random.choice(image_names)for i in range(4)]
random_images<define_variables>
result_1=pd.read_csv(".. /input/lgb-argu-0407/lgb_submission.csv")
 result_2=pd.read_csv(".. /input/lgb-without-argu-0405/lgb_submission.csv")
 result_3=pd.read_csv(".. /input/no-training-challenge/submission.csv")
 result_4=pd.read_csv(".. /input/nffm-0405-xdeepfm/nffm_submission.csv")
 result_5=pd.read_csv(".. /input/lgb-2-leaves-augment/lgb_submission.csv")
 result_6=pd.read_csv(".. /input/lgb-2-leaves-augment-mine/lgb_submission.csv")
 result_7=pd.read_csv(".. /input/lgb-noaug-pdf200/lgb_submission.csv" )
train_dir = "/kaggle/input/siim-isic-melanoma-classification/jpeg/train/"<define_variables>
result_1['index_1']=pd.DataFrame(rankdata(result_1['target'].tolist())) /len(result_1)
 result_2['index_2']=pd.DataFrame(rankdata(result_2['target'].tolist())) /len(result_2)
 result_3['index_3']=pd.DataFrame(rankdata(result_3['target'].tolist())) /len(result_3)
 result_4['index_4']=pd.DataFrame(rankdata(result_4['target'].tolist())) /len(result_4)
 result_5['index_5']=pd.DataFrame(rankdata(result_5['target'].tolist())) /len(result_5)
 result_6['index_6']=pd.DataFrame(rankdata(result_6['target'].tolist())) /len(result_6)
 result_7['index_7']=pd.DataFrame(rankdata(result_7['target'].tolist())) /len(result_7 )
SEED = 42
BATCH_SIZE = 32 * strategy.num_replicas_in_sync
SIZE = [512,512]
LR = 0.00004
EPOCHS = 12
WARMUP = 5
WEIGHT_DECAY = 0
LABEL_SMOOTHING = 0.05
TTA = 4<define_variables>
pri_lb=np.load(".. /input/list-of-fake-samples-and-public-private-lb-e2795a/private_LB.npy")
 pub_lb=np.load(".. /input/list-of-fake-samples-and-public-private-lb-e2795a/public_LB.npy")
 df_test_new=result_1.iloc[list(pri_lb)+list(pub_lb),:][['ID_code']]
df_test_new.head()
def seed_everything(SEED):
np.random.seed(SEED)
 tf.random.set_seed(SEED)
 seed_everything(SEED)
 train_filenames = tf.io.gfile.glob(GCS_PATH + '/train*.tfrec')
 test_filenames = tf.io.gfile.glob(GCS_PATH + '/test*.tfrec' )<split>
df_test_new['real']=1
df_test_new.head()
train_filenames,valid_filenames = train_test_split(train_filenames,test_size = 0.2,random_state = SEED )<normalization>
result_avg=pd.merge(result_1,result_2,on='ID_code')
 result_avg=pd.merge(result_avg,result_3,on='ID_code')
 result_avg=pd.merge(result_avg,result_4,on='ID_code')
 result_avg=pd.merge(result_avg,result_5,on='ID_code')
 result_avg=pd.merge(result_avg,result_6,on='ID_code')
 result_avg=pd.merge(result_avg,result_7,on='ID_code' )
def decode_image(image):
image = tf.image.decode_jpeg(image, channels=3)
 image = tf.cast(image, tf.float32)/255.0
image = tf.reshape(image, [*SIZE, 3])
 return image
def data_augment(image, label=None, seed=SEED):
image = tf.image.rot90(image,k=np.random.randint(4))
image = tf.image.random_flip_left_right(image, seed=seed)
 image = tf.image.random_flip_up_down(image, seed=seed)
 if label is None:
return image
else:
return image, label
def read_labeled_tfrecord(example):
LABELED_TFREC_FORMAT = {
"image": tf.io.FixedLenFeature([], tf.string),
"target": tf.io.FixedLenFeature([], tf.int64), }
example = tf.io.parse_single_example(example, LABELED_TFREC_FORMAT)
 image = decode_image(example['image'])
 label = tf.cast(example['target'], tf.int32)
 return image, label
def read_unlabeled_tfrecord(example):
UNLABELED_TFREC_FORMAT = {
"image": tf.io.FixedLenFeature([], tf.string),
"image_name": tf.io.FixedLenFeature([], tf.string), }
example = tf.io.parse_single_example(example, UNLABELED_TFREC_FORMAT)
 image = decode_image(example['image'])
 image_name = example['image_name']
return image, image_name
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)
.with_options(ignore_order)
.map(read_labeled_tfrecord if labeled else read_unlabeled_tfrecord, num_parallel_calls=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)
 def plot_transform(num_images):
plt.figure(figsize=(30,10))
x = load_dataset(train_filenames, labeled=False)
 image,_ = iter(x ).next()
for i in range(1,num_images+1):
plt.subplot(1,num_images+1,i)
 plt.axis('off')
 image = data_augment(image=image)
 plt.imshow(image )<normalization>
result_avg=result_avg.merge(df_test_new,on='ID_code',how='left')
 result_avg.head()
plot_transform(7 )<define_variables>
result_avg.fillna(0,inplace=True)
 result_avg.real.value_counts()
train_dataset =(load_dataset(train_filenames, labeled=True)
.map(data_augment, num_parallel_calls=AUTO)
.shuffle(SEED)
.batch(BATCH_SIZE,drop_remainder=True)
.repeat() 
.prefetch(AUTO))
valid_dataset =(load_dataset(valid_filenames, labeled=True)
.batch(BATCH_SIZE)
.cache() 
.prefetch(AUTO))<choose_model_class>
index_list=[]
for i in result_avg.columns:
if 'index_' in i:
index_list.append(i)
 result_avg['target']=0.0
for i in index_list:
result_avg['target']+=result_avg[i]/len(index_list )
<train_model><EOS> 
result=result_avg[['ID_code','target']]
ymd=time.strftime("%Y%m%d")
 hms=time.strftime("%H%M%S")
 name="blend_all_{0}_{1}.csv".format(ymd,hms)
 result.to_csv(name,encoding='utf-8',index=None )