Kaggle competition: SIIM-ACR Pneumothorax Segmentation
t = time.time()
batch_size=2*86
history = model.fit_generator(data_gen.flow(X_train,y_train,batch_size=batch_size),epochs=15, validation_data=(X_dev,y_dev),
steps_per_epoch=np.ceil(X_train.shape[0] / batch_size),use_multiprocessing=True,
callbacks=[lr_reducer])
 print("Time {}".format(time.time() -t))
submit(model )<set_options>
df_sub_list = [pd.read_csv(f)for f in glob(os.path.join("/", "kaggle", "input", "*", "*.csv")) ]
%matplotlib inline<load_pretrained>
iid_list = df_sub_list[0]["ImageId"].unique()
print(f"{len(iid_list)} unique image IDs." )
im = Image.open("/kaggle/input/test-image/shutterstock_aero.jpg" )<set_options>
min_solutions = 3
assert(min_solutions >= 1 and min_solutions <= len(df_sub_list)) , \
"min_solutions has to be a number between 1 and the number of submission files"
emboss = [-2,-1,0,-1,1,1,0,1,2]
kernel = ImageFilter.Kernel(( 3,3), emboss)
 im2 = im.filter(kernel)
 plt.figure(figsize=(10,8))
plt.xticks=[]
imshow(im2);<import_modules>
df_avg_sub = pd.DataFrame(columns=["ImageId", "EncodedPixels"])
 df_avg_sub_idx = 0
for iid in tqdm_notebook(iid_list):
avg_mask = np.zeros(( 1024,1024))
for df_sub in df_sub_list:
rles = df_sub.loc[df_sub["ImageId"]==iid, "EncodedPixels"]
for rle in rles:
if "-1" not in str(rle):
avg_mask += rle2mask(rle, 1024, 1024)/ float(len(df_sub_list))
avg_mask =(avg_mask >=(min_solutions * 255./ float(len(df_sub_list)))).astype("uint8")
 avg_rle_list = []
if avg_mask.max() > 0:
labeled_avg_mask, n_labels = skimage.measure.label(avg_mask, return_num=True)
 for label in range(1, n_labels+1):
avg_rle = mask2rle(( 255 *(labeled_avg_mask == label)).astype("uint8"), 1024, 1024)
 avg_rle_list.append(avg_rle)
 else:
avg_rle_list.append("-1")
 for avg_rle in avg_rle_list:
df_avg_sub.loc[df_avg_sub_idx] = [iid, avg_rle]
df_avg_sub_idx += 1
from keras.models import Sequential
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.layers import Dense
from keras.layers import Flatten
from keras.layers import Dropout
import numpy as np
import pandas as pd
from keras.utils import to_categorical
import collections
from sklearn.model_selection import train_test_split
from keras.preprocessing.image import ImageDataGenerator<set_options>
df_avg_sub["ImageId"].nunique()
<load_from_csv><EOS> 
df_avg_sub.to_csv("average_submission.csv", index=False )