Skip to content

TensorFlowの処理

Keras/TensorFlow

ソース フォルダ
Pi /home/pi/env/lib/python3.5/site-packages/donkeycar/parts/keras.py
Github https://github.com/autorope/donkeycar/blob/dev/donkeycar/parts/keras.py

keras.jsのKerasLinearメソッドの学習済みモデルに、画像を渡し、結果が返ってくるまでの時間をFPSで表示する。

keras.js

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import time

class KerasLinear(KerasPilot):
    def __init__(self, model=None, num_outputs=None, *args, **kwargs):
        super(KerasLinear, self).__init__(*args, **kwargs)
        if model:
            self.model = model
        elif num_outputs is not None:
            self.model = default_linear()
        else:
            self.model = default_linear()

    def run(self, img_arr):
        start_time = time.perf_counter()
        img_arr = img_arr.reshape((1,) + img_arr.shape)
        outputs = self.model.predict(img_arr)
        print("FPS: ", 1.0 / (time.perf_counter() - start_time))
        # print(len(outputs), outputs)
        steering = outputs[0]
        throttle = outputs[1]
        return steering[0][0], throttle[0][0]