2017-12-07 1 views
0

最近、私は、TFLearnを使ってカスタマイズされた深い神経ネットモデルを構築しました.Triearnは、scikit-learn見積もりAPIに深く学ぶと主張しています。私はモデルを訓練して予測をすることができましたが、スコアリング(評価)機能を働かせることができなかったので、クロスバリデーションはできませんでした。私はTFLearnについて様々なところで質問をしましたが、私は何の反応も得ていませんでした。自分自身のtf.Estimatorを構築すると、model_paramsはmodel_dirをどのように上書きしましたか? RuntimeWarning?

TensorFlow自体に見積もりクラスがあるようです。だから私はTFLearnを脇に置いています、そして、私はhttps://www.tensorflow.org/extend/estimatorsのガイドに従おうとしています。どういうわけか私は彼らが属していない変数を取得するように管理しています。誰も私の問題を見つけることができますか?私はコードと出力を投稿します。

注:もちろん、出力の上部にRuntimeWarningが表示されます。私はこの警告への言及をオンラインで見つけましたが、今まで誰もがそれが無害だと主張しています。 (私はデフォルトのまま)model_dirが何らかの形で値にバインドされ、私が間違っていた正確に何を見ることができます

import tensorflow as tf 
from my_library import Database, l2_angle_distance 


def my_model_function(topology, params): 

    # This function will eventually be a function factory. This should 
    # allow easy exploration of hyperparameters. For now, this just 
    # returns a single, fixed model_fn. 

    def model_fn(features, labels, mode): 

     # Input layer 
     net = tf.layers.conv1d(features["x"], topology[0], 3, activation=tf.nn.relu) 
     net = tf.layers.dropout(net, 0.25) 
     # The core of the network is here (convolutional layers only for now). 
     for nodes in topology[1:]: 
      net = tf.layers.conv1d(net, nodes, 3, activation=tf.nn.relu) 
      net = tf.layers.dropout(net, 0.25) 
     sh = tf.shape(features["x"]) 
     net = tf.reshape(net, [sh[0], sh[1], 3, 2]) 
     predictions = tf.nn.l2_normalize(net, dim=3) 

     # PREDICT EstimatorSpec 
     if mode == tf.estimator.ModeKeys.PREDICT: 
      return tf.estimator.EstimatorSpec(mode=mode, 
        predictions={"vectors": predictions}) 

     # TRAIN or EVAL EstimatorSpec 
     loss = l2_angle_distance(labels, predictions) 
     optimizer = tf.train.GradientDescentOptimizer(learning_rate=params["learning_rate"]) 
     train_op = optimizer.minimize(loss=loss, global_step=tf.train.get_global_step()) 
     return tf.estimator.EstimatorSpec(mode, predictions, loss, train_op) 

    return model_fn 

##=================================================================== 

window = "whole" 
encoding = "one_hot" 
db = Database("/home/bwllc/Documents/Files for ML/compact") 

traindb, testdb = db.train_test_split() 
train_features, train_labels = traindb.values(window, encoding) 
test_features, test_labels = testdb.values(window, encoding) 

# Create the model. 
tf.logging.set_verbosity(tf.logging.INFO) 
LEARNING_RATE = 0.01 
topology = (60,40,20) 
model_params = {"learning_rate": LEARNING_RATE} 
model_fn = my_model_function(topology, model_params) 
model = tf.estimator.Estimator(model_fn, model_params) 
print("\nmodel_dir? No? Why not? ", model.model_dir, "\n") # This documents the error 

# Input function. 
my_input_fn = tf.estimator.inputs.numpy_input_fn({"x" : train_features}, train_labels, shuffle=True) 

# Train the model. 
model.train(input_fn=my_input_fn, steps=20) 

OUTPUT

/usr/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6 
    return f(*args, **kwds) 
INFO:tensorflow:Using default config. 
INFO:tensorflow:Using config: {'_model_dir': {'learning_rate': 0.01}, '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': None, '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x7f0b55279048>, '_task_type': 'worker', '_task_id': 0, '_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1} 

model_dir? No? Why not? {'learning_rate': 0.01} 

INFO:tensorflow:Create CheckpointSaverHook. 
Traceback (most recent call last): 
    File "minimal_estimator_bug_example.py", line 81, in <module> 
    model.train(input_fn=my_input_fn, steps=20) 
    File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/estimator/estimator.py", line 302, in train 
    loss = self._train_model(input_fn, hooks, saving_listeners) 
    File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/estimator/estimator.py", line 756, in _train_model 
    scaffold=estimator_spec.scaffold) 
    File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/basic_session_run_hooks.py", line 411, in __init__ 
    self._save_path = os.path.join(checkpoint_dir, checkpoint_basename) 
    File "/usr/lib/python3.6/posixpath.py", line 78, in join 
    a = os.fspath(a) 
TypeError: expected str, bytes or os.PathLike object, not dict 

------------------ 
(program exited with code: 1) 
Press return to continue 

:多分それは...

CODEではありません私はmodel_paramsを対象としました。これは私のコードでどのように起こったのですか?私はそれを見ることができません。

誰でもアドバイスや提案があれば、大変ありがとうございます。ありがとう!

答えて

2

を作成するときにmodel_parammodel_dirとしているだけであるからです。 tensorflow documentationから

推定__init__機能:2番目の引数がmodel_dir 1であるか

__init__(
    model_fn, 
    model_dir=None, 
    config=None, 
    params=None 
) 

注意してください。 paramsのみを指定する場合は、キーワード引数として渡す必要があります。

model = tf.estimator.Estimator(model_fn, params=model_params) 

または指定したすべての以前の位置引数:

model = tf.estimator.Estimator(model_fn, None, None, model_params) 
+0

おかげで、Lescurel!私は変更を加え、エラーを修正しました。 TensorFlowは、不正な方法で動作しており、TypeErrorが発生しているはずです。また、私はTensorFlowのドキュメントは現在それ自身と矛盾していると信じています。前に参照した、私が従っていたページ、https://www.tensorflow.org/extend/estimators:を見てください。これとは対照的に、独自の見積もりをゼロから作成する場合、コンストラクターは2つのハイレベルModel configuration、model_fn、paramsのパラメータ: 'nn = tf.estimator.Estimator(model_fn = param = model_params)' " –

+0

私はあなたに不快な動作に同意し、Tensorflowの開発者に通知することができます。 (あなたが気に入ったら、[github issue](https://github.com/tensorflow/tensorflow/issues)を開きます)。しかし、あなたが提供したリンクでは、キーワードの引数があり、 "* tf.estimatorのあらかじめ定義された回帰子や分類子のように、Estimatorの初期化子は一般的な設定引数model_dirとconfig。*も受け付けます。それはもっと明確にすることができると私は同意するが、情報はここにある。 – Lescurel

関連する問題