2016-07-07 18 views
2

ifelse私はスクリプトlstm_ptb.pyを実行しようとしていますが、それは次の行のためにはTypeErrorを投げている:Theano:例外TypeError

shrink_factor = ifelse(T.gt(norm_gparams,max_grad_norm),max_grad_norm/norm_gparams,1.) 

これは、この行を達成しようとしているものです。

if norm_gparams > max_grad_norm: 
    shrink_factor = max_grad_norm/norm_gparams 
else: 
    shrink_factor = 1. 

それは言う:

TypeError: The two branches should have identical types, but they are TensorType(float64, scalar) and TensorType(float32, scalar) respectively. This error could be raised if for example you provided a one element list on the then branch but a tensor on the else branch

どうすればエラーを解決してください?お返事は

答えて

0

1.else部分に起因する問題です。デフォルトでは、float32タイプとして割り当てられます。

shrink_factor = ifelse(T.gt(norm_gparams,max_grad_norm),max_grad_norm/norm_gparams,np.float64(1.)) 

をかmax_grad_norm/norm_gparams値に変換:あなたはそれを変換する必要があり

shrink_factor = ifelse(T.gt(norm_gparams,max_grad_norm),(max_grad_norm/norm_gparams).astype('float32'),1.) 

をので、両方の値が同じ型を持っている