0
TensorForestEstimatorを使用してTensorflowランダムフォレストをトレーニングしようとすると、TypeErrorが発生します。TensorflowトレーニングのタイプエラーTensorForestEstimatorを使用したランダムフォレスト
TypeError: Input 'input_data' of 'CountExtremelyRandomStats' Op has type float64 that does not match expected type of float32.
私は、Python 2.7とPython 3を使用して試してみた、と私は(tf.castを使用して試してみた)のfloat32にすべてを置くために、それは役立ちません。私は実行時にデータ型をチェックしており、float32です。問題は私が提供するデータ(すべてのフロートのCSV)ではないようですので、ここからどこに行くのかは分かりません。
私が試してみることのできる提案は、非常に高く評価されます。
コード:
# Build an estimator.
def build_estimator(model_dir):
params = tensor_forest.ForestHParams(
num_classes=2, num_features=760,
num_trees=FLAGS.num_trees, max_nodes=FLAGS.max_nodes)
graph_builder_class = tensor_forest.RandomForestGraphs
if FLAGS.use_training_loss:
graph_builder_class = tensor_forest.TrainingLossForest
# Use the SKCompat wrapper, which gives us a convenient way to split in-memory data into batches.
return estimator.SKCompat(random_forest.TensorForestEstimator(params, graph_builder_class=graph_builder_class, model_dir=model_dir))
# Train and evaluate the model.
def train_and_eval():
# load datasets
training_set = pd.read_csv('/Users/carl/Dropbox/Docs/Python/randomforest_balanced_train.csv', dtype=np.float32, header=None)
test_set = pd.read_csv('/Users/carl/Dropbox/Docs/Python/randomforest_balanced_test.csv', dtype=np.float32, header=None)
print('###########')
print(training_set.loc[:,1].dtype) # this prints float32
# load labels
training_labels = pd.read_csv('/Users/carl/Dropbox/Docs/Python/randomforest_balanced_train_class.csv', dtype=np.int32, names=LABEL, header=None)
test_labels = pd.read_csv('/Users/carl/Dropbox/Docs/Python/randomforest_balanced_test_class.csv', dtype=np.int32, names=LABEL, header=None)
# define the path where the model will be stored - default is current directory
model_dir = tempfile.mkdtemp() if not FLAGS.model_dir else FLAGS.model_dir
print('model directory = %s' % model_dir)
# build the random forest estimator
est = build_estimator(model_dir)
tf.cast(training_set, tf.float32) #error occurs with/without casts
tf.cast(test_set, tf.float32)
# train the forest to fit the training data
est.fit(x=training_set, y=training_labels) #this line throws the error
ありがとうございました – Carl
こんにちは、私は似たような問題を抱えていましたが、この解決策は私のためには機能しませんか?私の問題がこの問題と同じかどうか分からないのですか? https://stackoverflow.com/questions/45392269/tensorflow-skcompat-converting-float32-values-in-pandas-dataframe-to-tf-float64 – Mark