Repository navigation
Expand file tree
/
Copy pathevaluate.py
More file actions
executable file
·82 lines (72 loc) · 2.09 KB
/
Copy pathevaluate.py
File metadata and controls
executable file
·82 lines (72 loc) · 2.09 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 9 10:21:10 2017
@author: ronshiff
"""
import keras
import pandas as pd
import numpy as np
import time
file_out = 'submission.csv'
# load model
model = keras.models.load_model('model1')
filename = 'test.json/data/processed/test.json'
df = pd.read_json(filename,orient='records')
df_csv = pd.read_csv('sample_submission.csv')
#
start = time.time()
vec = []
#
for index, row in df_csv.iterrows():
item2eval = df[df['id'] == row['id']].iloc[0]
imag1 = item2eval['band_1']
imag2 = item2eval['band_2']
img1 = np.array(imag1)
img2 = np.array(imag2)
img1 = np.reshape(img1,(75,-1))
img2 = np.reshape(img2,(75,-1))
img = np.array([img1,img2,np.zeros(img1.shape)]).transpose()
img = (img - np.mean(img))/np.std(img)
vec.append(img)
#x = np.expand_dims(img, axis=0) #add dimension to be 4 dim
xx = np.array(vec)
prob = model.predict_proba(xx)
#
for index, row in df_csv.iterrows():
df_csv.set_value(index,'is_iceberg',prob[index])
df_csv.to_csv(file_out, sep=',', index = False ,encoding='utf-8')
# =============================================================================
#
# end = time.time()
# print(end - start)
#
#
# cnt = 0
#
# #
# import time
# start = time.time()
#
# #
# for index, row in df_csv.iterrows():
# cnt += 1
# print(cnt)
# if (cnt == 50):
# break
# item2eval = df[df['id'] == row['id']].iloc[0]
# imag1 = item2eval['band_1']
# imag2 = item2eval['band_2']
# img1 = np.array(imag1)
# img2 = np.array(imag2)
# img1 = np.reshape(img1,(75,-1))
# img2 = np.reshape(img2,(75,-1))
# img = np.array([img1,img2,np.zeros(img1.shape)]).transpose()
# img = (img - np.mean(img))/np.std(img)
# x = np.expand_dims(img, axis=0) #add dimension to be 4 dim
# prob = model.predict_proba(x)
# df_csv.iloc[index]['is_iceberg'] = prob
#
# end = time.time()
# print(end - start)
#
# =============================================================================