-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsubmit.py
47 lines (36 loc) · 1.61 KB
/
submit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# https://www.kaggle.com/vasilkor/complete-process-using-resnet-as-a-starting-point
import glob
import cv2
import numpy as np
import pandas as pd
from keras.models import load_model
# file_name = 'final_folder/vgg16_final'
# file_name = 'final_folder/vgg19_final'
# file_name = 'final_folder/res50_final'
# file_name = 'final_folder/inception_final'
file_name = 'final_folder/xception_final'
model = load_model('%s.h5' % file_name)
sample_subm = pd.read_csv("../sample_submission_stg2.csv")
ids = sample_subm['image_name'].values
for id in ids:
print('Predict for image {}'.format(id))
files = glob.glob("../input/test/" + id)
image_list = []
for f in files:
image = cv2.imread(f)
image = cv2.resize(image, (299, 299)) # xception, inception = 299, resnet,vgg = 224
image = image.astype('float32')
image = image / 255
image_list.append(image)
image_list = np.array(image_list)
# image_list = np.expand_dims(image_list, axis=0)
predictions = model.predict(image_list, verbose=1, batch_size=1)
# Denominator = sum(predictions)
# predictions[0,0] = predictions[0,0] / Denominator
# predictions[0,1] = predictions[0,1] / Denominator
# predictions[0,2] = predictions[0,2] / Denominator
# np.clip(predictions, 0.10, 0.90, out=predictions)
sample_subm.loc[sample_subm['image_name'] == id, 'Type_1'] = predictions[0, 0]
sample_subm.loc[sample_subm['image_name'] == id, 'Type_2'] = predictions[0, 1]
sample_subm.loc[sample_subm['image_name'] == id, 'Type_3'] = predictions[0, 2]
sample_subm.to_csv("%s_noclip_stg2.csv" % file_name, index=False)