2017-12-30 8 views
1

동적 rnn 견적서를 교육하려고하지만 회귀 데이터를 사용하여 올바른 데이터 모양을 식별 할 수 없습니다. tensorflow DynamicRnnEstimator - 접두사 또는 접미사 없음

import random 
import numpy as np 
import tensorflow as tf 
from tensorflow.contrib.learn import DynamicRnnEstimator 
from tensorflow.contrib.learn.python.learn.estimators.constants import (
    ProblemType, 
) 
from tensorflow.contrib.learn.python.learn.estimators.rnn_common import (
    PredictionType, 
) 
from tensorflow.contrib.layers import real_valued_column 

X = np.random.uniform(size=(1000, 10)) 
M = X.shape[0] 
N = X.shape[1] 
y = np.random.uniform(size=1000) 

seq_feat_cols = [real_valued_column(column_name='X', dimension=N)] 
rnn = DynamicRnnEstimator(ProblemType.LINEAR_REGRESSION, 
          PredictionType.SINGLE_VALUE, 
          sequence_feature_columns=seq_feat_cols) 

def get_batch(): 
    period_steps = 20 
    start = random.randint(0, (M - 1) - period_steps - 1) 
    end = start + period_steps 
    x_tf = tf.expand_dims(X[start:end], axis=0) 
    return {'X': x_tf}, tf.constant(y[start:end]) 

rnn.fit(input_fn=get_batch, steps=10) 

가 산출된다 : 나는 아무 소용이 내 ndarray의 양쪽에있는 차원을 확장하려고했습니다

ValueError: Provided a prefix or suffix of None: 1 and None 

; 어떤 제안이라도 대단히 감사하겠습니다!

답변

1

DynamicRNNEstimator의 생성자에 제공되지 않았기 때문에 그 모양이 비슷합니다. 기타 문제 :

  • input_fn 지정한 사용자는 한 번만 실행됩니다. 따라서 TensorFlow 그래프를 작성해야합니다.이 그래프는 데이터 집합을 반복하거나 임의의 TensorFlow 연산을가집니다.
  • timestep 당 하나의 라벨이있는 것 같습니다.이 경우 예측 유형으로 SINGLE_VALUE이 아닌 MULTIPLE_VALUE이 필요합니다.

    import random 
    import numpy as np 
    import tensorflow as tf 
    from tensorflow.contrib.learn import DynamicRnnEstimator 
    from tensorflow.contrib.learn.python.learn.estimators.constants import (
        ProblemType, 
    ) 
    from tensorflow.contrib.learn.python.learn.estimators.rnn_common import (
        PredictionType, 
    ) 
    from tensorflow.contrib.layers import real_valued_column 
    
    X = np.random.uniform(size=(1000, 10)) 
    M = X.shape[0] 
    N = X.shape[1] 
    y = np.random.uniform(size=1000) 
    
    seq_feat_cols = [real_valued_column('X')] 
    rnn = DynamicRnnEstimator(ProblemType.LINEAR_REGRESSION, 
              PredictionType.MULTIPLE_VALUE, 
              num_units=5, 
              sequence_feature_columns=seq_feat_cols) 
    
    def get_batch(): 
        period_steps = 20 
        start = tf.random_uniform(
         shape=(), 
         minval=0, 
         maxval=(M - 1) - period_steps - 1, 
         dtype=tf.int32) 
        end = start + period_steps 
        x_sliced = tf.constant(X)[None, start:end, :] 
        y_sliced = tf.constant(y)[None, start:end] 
        x_sliced.set_shape((1, period_steps, N)) 
        y_sliced.set_shape((1, period_steps)) 
        return {'X': x_sliced}, y_sliced 
    
    rnn.fit(input_fn=get_batch, steps=10) 
    
    :
  • 추정기는 배치 치수 함께 그 모든 퍼팅

(그것은 하나 일 수있다) 예상