Create a TensorFlow graph with multiple random forest (RandomForestGraphs)

a 夏天 提交于 2019-12-24 18:50:14

问题


Is it possible to create a graph in TensorFlow containing multiple RandomForestGraphs?

Instead of one random forest with num_classes=3 I want to have three random forests, one classifying only classes 1 and 2, the second one classes 2 and 3 and the third classes 3 and 1. In front of these classifiers is a arbitrator element deciding which forest to train or infer based on the current class (i.e., class 1 -> tree 1, class 2 -> tree 2, ...). This way i hope to restrict the possible outcomes in a simple way: input of (previously) class 1 can only result in class 1 or 2, etc.

Now, the problem is that Tensorflow internally uses a graph and as soon as I try to create a second RandomForestGraphs, I get an error:

ValueError: Variable device_dummy_0 already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope?

My understanding is, that the internal default graph is configured after the first call of RandomForestGraphs and the second call is seen as redundant, basically orverwriting the first one. Code used:

hp0 = tensor_forest.ForestHParams(num_classes=2, num_features=num_features, regression=False, num_trees=num_trees, max_nodes=max_nodes).fill()
hp1 = tensor_forest.ForestHParams(num_classes=2, num_features=num_features, regression=False, num_trees=num_trees, max_nodes=max_nodes).fill()

forest_graph0 = tensor_forest.RandomForestGraphs(hp0)
forest_graph1 = tensor_forest.RandomForestGraphs(hp1) # ERROR

Is there a more elegant way to solve this? Or can I create and combine two graphs in TensorFlow somehow?

来源:https://stackoverflow.com/questions/56278693/create-a-tensorflow-graph-with-multiple-random-forest-randomforestgraphs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!