Skip to content

Instantly share code, notes, and snippets.

@akimach
Last active October 1, 2017 11:51
Show Gist options
  • Select an option

  • Save akimach/3c34cbb9743c03eb5bb4d4b429b98da6 to your computer and use it in GitHub Desktop.

Select an option

Save akimach/3c34cbb9743c03eb5bb4d4b429b98da6 to your computer and use it in GitHub Desktop.
GestureAI ― Keras + CoreML + iOS 11を用いた RNNによるジェスチャー認識 ref: http://qiita.com/akimach/items/d43cd04b5de5fa99bb6a
timesteps = 40 # 最大系列長
input_dim = 3 # 入力次元
df = pd.read_csv('example.csv')
seq = df.as_matrix()
seq_length = seq.shape[0] # 対象となるデータの系列長
seq_0padding = np.r_[seq, np.zeros((timesteps-seq_length, input_dim))]
# ハイパーパラメータの候補
param_grid = {
"rnn_cell": ['LSTM', 'GRU'],
"n_hidden": [128, 256, 512, 1024,],
}
model = KerasClassifier(build_fn=rnn, nb_epoch=epochs, batch_size=batch_size, verbose=1)
clf = GridSearchCV(estimator=model, param_grid=param_grid, cv=n_cv, scoring='accuracy')
# グリッドサーチの実行
res = clf.fit(X, y)
# 結果の表示
print(res.cv_results_)
# ベストなパラメータととその正答率
print("Hyper Parameters:", res.best_params_, "Accuracy:", res.best_score_)
import coremltools
# 保存先のパス
model.fit(...) # 学習済みのモデル
# (1) モデルのオブジェクトを渡す場合
coreml_model =coremltools.converters.keras.convert(model)
coreml_model.save('models/GestureAI.mlmodel')
# (2) ファイルパスを渡す場合
path = 'models/GestureAI.h5'
model.save(path)
coreml_model =coremltools.converters.keras.convert(path)
coreml_model.save('models/GestureAI.mlmodel')
coreml_model.author = 'Hoge'
coreml_model.license = 'MIT'
coreml_model.short_description = 'My neural network'
let targetData = ... // 推論させるデータ
let gestureAI = GestureAI()
guard let output = try? gestureAI.prediction(input:
GestureAIInput(input1: targetData)) else {
fatalError("Unexpected runtime error.")
}
print(output)
$ git clone https://github.com/akimach/GestureAI-CoreML-iOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment