Browse Source

add live eval

James Jeon 1 year ago
parent
commit
7c7abf390c
2 changed files with 104 additions and 3 deletions
  1. 11
    3
      eval.py
  2. 93
    0
      live_eval.py

+ 11
- 3
eval.py View File

@@ -9,7 +9,9 @@ import numpy as np
9 9
 
10 10
 sess = tf.InteractiveSession()
11 11
 saver = tf.train.Saver()
12
-saver.restore(sess, "./weight/MSE_without-0_4.model")
12
+saver.restore(sess, "./weight/SSC_epoch_14_LR_0.0001.model")
13
+
14
+data_list = []
13 15
 
14 16
 file_list = os.listdir('/raw_data/eval_data')
15 17
 for file in file_list:
@@ -34,7 +36,7 @@ for file in file_list:
34 36
 
35 37
 			# if the steering wheel angle in in right to the center
36 38
 			if(int_data > 550):
37
-				int_data = int_data - 4095
39
+				int_data = int_data - 4096
38 40
 				int_decimal = 1 - int_decimal 
39 41
 				final_data = int_data - int_decimal
40 42
 			else:
@@ -43,7 +45,13 @@ for file in file_list:
43 45
 
44 46
 			deg = model.y.eval(feed_dict={model.x: [img], model.keep_prob: 1.0})[0][0]
45 47
 
46
-			print(deg, final_data)
48
+			difference = ((final_data+16)-(deg+16))/(final_data+16)
49
+			if difference < 0:
50
+				difference = difference * -1
51
+			difference = difference * 100
52
+			print(deg, final_data, difference)
53
+
54
+
47 55
 
48 56
 
49 57
 			    

+ 93
- 0
live_eval.py View File

@@ -0,0 +1,93 @@
1
+#!/usr/bin/env python 
2
+
3
+import os
4
+import tensorflow as tf
5
+import model
6
+import params
7
+import cv2
8
+import numpy as np
9
+
10
+cap = cv2.VideoCapture(0)
11
+cap.set(3,300) # set height
12
+cap.set(4,200) # set width
13
+
14
+sess = tf.InteractiveSession()
15
+saver = tf.train.Saver()
16
+saver.restore(sess, "./weight/SSC_epoch_14_LR_0.0001.model")
17
+
18
+def get_frame():
19
+	# read the frame from webcam
20
+	_, frame = cap.read()
21
+	tmp = cv2.resize(frame,(0,0),fx=0.8, fy=0.8)
22
+	tmp = cv2.flip(tmp,0)
23
+	tmp = cv2.flip(tmp,1)
24
+	if params.img_channels != 3:
25
+		tmp = cv2.cvtColor(tmp, cv2.COLOR_BGR2GRAY)
26
+	img = (tmp[70:-5,::]).reshape(params.img_height, params.img_width, params.img_channels)
27
+
28
+	return img, frame
29
+
30
+def get_angle():
31
+    while(True):
32
+	# get one can data
33
+        can_data = str(bus.recv())
34
+	# check it is steering angle, if yes then stop the loop
35
+        if(can_data.find("ID: 0025") > 0):
36
+            break
37
+
38
+    # change the can data (HEX) to numerical data
39
+	tmp = can_data
40
+	hex_data = tmp[-23:-21] + tmp[-20:-18]
41
+	hex_decimal = tmp[-3:-1]
42
+	int_data = int(hex_data, 16)
43
+	int_decimal = int(hex_decimal, 16) / 256
44
+
45
+			# if the steering wheel angle in in right to the center
46
+	if(int_data > 550):
47
+		int_data = int_data - 4096
48
+		int_decimal = 1 - int_decimal 
49
+		final_data = int_data - int_decimal
50
+	else:
51
+		# put the int and the decimal together
52
+		final_data = int_data + int_decimal
53
+
54
+    return final_data
55
+
56
+def main():
57
+	# discard first 40 frames to give time for webcam to get the proper exposure
58
+	for i in range(40):
59
+			get_angle()
60
+			get_frame()
61
+			print(i, "discarded")
62
+
63
+	while True:
64
+		angle = get_angle()
65
+		img, frame = get_frame()
66
+
67
+		deg = model.y.eval(feed_dict={model.x: [img], model.keep_prob: 1.0})[0][0]
68
+		difference = ((final_data+16)-(deg+16))/(final_data+16)
69
+		if difference < 0:
70
+			difference = difference * -1
71
+		difference = difference * 100
72
+
73
+		predicted = "predicted : " + str(deg)
74
+		actual = "actual : " + str(final_data)
75
+		percent = "% difference : " + str(difference)
76
+
77
+		cv2.putText(image,predicted,(10,30), cv2.FONT_HERSHEY_COMPLEX, 1,(255,255,255),2,cv2.LINE_AA)
78
+		cv2.putText(image,actual,(50,30), cv2.FONT_HERSHEY_COMPLEX, 1,(255,255,255),2,cv2.LINE_AA)
79
+		cv2.putText(image,percent,(70,30), cv2.FONT_HERSHEY_COMPLEX, 1,(255,255,255),2,cv2.LINE_AA)
80
+		
81
+		cv2.imshow('frame', frame)
82
+
83
+		if cv2.waitKey(1) & 0xFF == ord('q'):
84
+				break
85
+		
86
+
87
+main()
88
+
89
+cap.release()
90
+cv2.destroyAllWindows()
91
+
92
+
93
+			    

Loading…
Cancel
Save