Kaggle competition: ASN10e Final Submission - Detect COML Faces
<SOS> metric: rmse Kaggle data source: asn10e-final-submission-detect-coml-faces<choose_model_class>
!wget https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_eye.xml
!wget https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_frontalface_default.xml
submit_confirmed=[]
submit_fatal=[]
for i in df1:
data = i.ConfirmedCases.astype('int32' ).tolist()
try:
model = SARIMAX(data, order=(1,1,0), seasonal_order=(1,1,0,12),measurement_error=True)
 model_fit = model.fit(disp=False)
 predicted = model_fit.predict(len(data), len(data)+34)
 new=np.concatenate(( np.array(data),np.array([int(num)for num in predicted])) ,axis=0)
 submit_confirmed.extend(list(new[-43:]))
except:
submit_confirmed.extend(list(data[-10:-1]))
for j in range(34):
submit_confirmed.append(data[-1]*2)
 data = i.Fatalities.astype('int32' ).tolist()
try:
model = SARIMAX(data, order=(1,1,0), seasonal_order=(1,1,0,12),measurement_error=True)
 model_fit = model.fit(disp=False)
 predicted = model_fit.predict(len(data), len(data)+34)
 new=np.concatenate(( np.array(data),np.array([int(num)for num in predicted])) ,axis=0)
 submit_fatal.extend(list(new[-43:]))
except:
submit_fatal.extend(list(data[-10:-1]))
for j in range(34):
submit_fatal.append(data[-1]*2)
<data_type_conversions>
svc = pickle.load(open("/kaggle/input/fire-facenet/svc.pkl", "rb"))
enc = pickle.load(open("/kaggle/input/fire-facenet/encoder.pkl", "rb"))
mod = "/kaggle/input/fire-facenet/nn4.small2.v1.h5"
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
 root = "/kaggle/input/asn10e-final-submission-coml-facial-recognition/"
infile = open(os.path.join(root,"person_id_mapping.csv"), "r")
 person_to_id = {line.split(",")[1][:-1]:int(line.split(",")[0])for line in infile if "person_id" not in line}
id_to_person = {person_to_id[key]:key for key in person_to_id}
sys.path.append("/kaggle/input/fire-facenet/models")
 nn4_small2_pretrained = create_model()
nn4_small2_pretrained.load_weights(mod)
 alignment = AlignDlib('/kaggle/input/fire-facenet/models/models/landmarks.dat' )
df_submit=pd.concat([pd.Series(np.arange(1,1+len(submit_confirmed))),pd.Series(submit_confirmed),pd.Series(submit_fatal)],axis=1)
 df_submit=df_submit.fillna(method='pad' ).astype(int )<merge>
ids = ["0_25", "0_34", "0_40", "0_37", "0_3", "0_2", "0_20", "0_27", "0_39", "0_33", "0_14", "0_17", "0_4", "0_46", "0_29", "0_35", "0_11", "0_41", "0_8", "0_42", "0_7", "0_1", "0_15", "0_0", "0_32", "0_16", "0_21", "0_13", "0_31", "0_30", "0_22", "0_19", "0_23", "0_24", "0_43", "0_36", "0_10", "0_44", "1_28", "1_26", "1_38", "1_45", "1_12", "1_9"]
ids0 = sorted([int(i.split("_")[1])for i in ids if i[0] == "0"])
 ids1 = sorted([int(i.split("_")[1])for i in ids if i[0] == "1"])
 pred = svc.decision_function(embedded)
 idx0 = np.asarray([i for i in range(len(X_paths)) if "0" in X_paths[i]])
 idx1 = np.asarray([i for i in range(len(X_paths)) if "1" in X_paths[i]] )
df_submit.rename(columns={0: 'ForecastId', 1: 'ConfirmedCases',2: 'Fatalities',}, inplace=True)
 complete_test= pd.merge(test, df_submit, how="left", on="ForecastId" )<save_to_csv>
!pip install munkres
df_submit.to_csv('submission.csv',header=['ForecastId','ConfirmedCases','Fatalities'],index=False)
 complete_test.to_csv('complete_test.csv',index=False)
<load_from_csv>
m = Munkres()
def find_labels(pred, ids):
mat = [[-1*dist[i] for i in range(len(dist)) if i in ids] for dist in pred]
matches = {i[0]:i[1] for i in m.compute(mat)}
labels = [ids[matches[i]] if i in matches else None for i in range(len(pred)) ]
return labels
labels1 = find_labels(pred[idx1],ids1)
 labels0 = find_labels(pred[idx0],ids0)
 y2 = []
j = 0
k = 0
for i in range(len(X_paths)) :
if i in idx0:
y2.append(labels0[j])
 j += 1
else:
y2.append(labels1[k])
 k+=1
sample_submission = pd.read_csv("/kaggle/input/covid19-global-forecasting-week-2/submission.csv")
 test = pd.read_csv("/kaggle/input/covid19-global-forecasting-week-2/test.csv")
 train = pd.read_csv("/kaggle/input/covid19-global-forecasting-week-2/train.csv")
 pop = pd.read_csv("/kaggle/input/pop2020/data.csv")
 test2=pd.read_csv("/kaggle/input/covid19-global-forecasting-week-2/test.csv")
 train2=pd.read_csv("/kaggle/input/pop2020/data.csv" )<rename_columns>
def find_data(pnum, pred, idx):
ind = 0
mx = -100
for i, p in enumerate(pred):
if p[pnum] > mx:
ind = i
mx = p[pnum]
fname = X_paths[idx[ind]]
fx, fy, fw, fh = F[idx[ind]]
return {"filename": fname, "person_id":fname.replace(".jpg", "_%d"%pnum), 'xmin': fx, 'xmax': fx+fw, 'ymin': fy, 'ymax': fy+fh, 'img': idx[ind]}
def find_labels(pred, ids):
mat = [[-1*dist[i] for i in range(len(dist)) if i in ids] for dist in pred]
matches = {i[0]:i[1] for i in m.compute(mat)}
print(matches)
 labels = [ids[matches[i]] if i in matches else None for i in range(len(pred)) ]
return labels
preds1 = pred[idx1]
preds0 = pred[idx0]
y3 = {**{pnum:find_data(pnum, preds1, idx1)for pnum in id_to_person if pnum in ids1}, **{pnum:find_data(pnum, preds0, idx0)for pnum in id_to_person if pnum in ids0}}