Comments (7)
@cweill Thanks for your great work!
If I want to combine simple cnn and simple dnn together, how could I do?
For example, I want to get a network "2_layer_dnn -> cnn -> cnn”
from adanet.
@JodyZXD: Good observation. The GIF just demos a simple example. The AdaNet framework supports a superset of the subnetworks and connections that the paper defines. You can recreate the neural network from the paper by passing the hidden_layer outputs through the Subnetwork.persisted_tensors
dict. This will make these tensors available across iterations.
For instance, you can do something like the following change to simple_dnn.py
:
def build_subnetwork(self,
features,
logits_dimension,
training,
iteration_step,
summary,
previous_ensemble):
"""See `adanet.subnetwork.Builder`."""
input_layer = tf.feature_column.input_layer(
features=features, feature_columns=self._feature_columns)
last_layer = input_layer
persisted_tensors = {_NUM_LAYERS_KEY: tf.constant(self._num_layers)}
for i in range(self._num_layers):
last_layer = tf.layers.dense(
last_layer,
units=self._layer_size,
activation=tf.nn.relu,
kernel_initializer=tf.glorot_uniform_initializer(seed=self._seed))
last_layer = tf.layers.dropout(
last_layer, rate=self._dropout, seed=self._seed, training=training)
hidden_layer_key = "hidden_layer_{}".format(i)
if previous_ensemble:
# Iteration t>0.
last_subnetwork = previous_ensemble.weighted_subnetworks[-1].subnetwork
last_layer = tf.concat([last_subnetwork.persisted_tensors[hidden_layer_key]), last_layer], axis=1)
# Store hidden layer outputs for subsequent iterations.
persisted_tensors[hidden_layer_key] = last_layer
logits = tf.layers.dense(
last_layer,
units=logits_dimension,
kernel_initializer=tf.glorot_uniform_initializer(seed=self._seed))
# Approximate the Rademacher complexity of this subnetwork as the square-
# root of its depth.
complexity = tf.sqrt(tf.to_float(self._num_layers))
with tf.name_scope(""):
summary.scalar("complexity", complexity)
summary.scalar("num_layers", self._num_layers)
return adanet.Subnetwork(
last_layer=last_layer,
logits=logits,
complexity=complexity,
persisted_tensors=persisted_tensors)
from adanet.
@cweill Thanks a lot! It's instructive for me!
I have another question here: will you give a GPU guide before long?
from adanet.
AdaNet works on GPU just like any other TensorFlow Estimator. Any guide on the web to do GPU training should get you started.
You can also try GPU on Colab by changing the runtime hardware to GPU
:
from adanet.
@cweil Thanks for the insight on building network! However I've tested the build_subnetwork code you posted above (plugging it into the SimpleDNNBuilder) and it does not work. I'm not getting how to exactly sample the network structural space as described in the paper. Any indication or additional piece of code would be most welcome!
from adanet.
An alternative approach can be the following builder
def build_subnetwork(self,
features,
logits_dimension,
training,
iteration_step,
summary,
previous_ensemble=None):
"""See `adanet.subnetwork.Builder`."""
input_layer = tf.to_float(features['x'])
kernel_initializer = tf.glorot_uniform_initializer(seed=self._seed)
last_layer = input_layer
for layer_size in self._layer_sizes:
last_layer = tf.layers.dense(
last_layer,
units=layer_size,
activation=self._activation,
kernel_initializer=kernel_initializer)
logits = tf.layers.dense(
last_layer,
units=logits_dimension,
kernel_initializer=kernel_initializer)
persisted_tensors = {
"num_layers": tf.constant(self._num_layers),
"layer_sizes": tf.constant(self._layer_sizes),
}
return adanet.Subnetwork(
last_layer=last_layer,
logits=logits,
complexity=self._measure_complexity(),
persisted_tensors=persisted_tensors)
and move the logic for exploring in the generator
def generate_candidates(self, previous_ensemble, iteration_number,
previous_ensemble_reports, all_reports):
"""See `adanet.subnetwork.Generator`."""
seed = self._seed
if seed is not None:
seed += iteration_number
# start with single layer
num_layers = 1
layer_sizes = [self.layer_block_size]
# take the maximum depth reached in previous iterations + 1
if previous_ensemble:
last_subnetwork = previous_ensemble.weighted_subnetworks[
-1].subnetwork
persisted_tensors = last_subnetwork.persisted_tensors
num_layers = tf.contrib.util.constant_value(
persisted_tensors["num_layers"])
layer_sizes = list(tf.contrib.util.constant_value(
persisted_tensors["layer_sizes"]))
# at each iteration we want to check if exdending any of the
# existing layes is good
candidates = list()
for extend_layer in range(num_layers):
new_sizes = layer_sizes[:]
new_sizes[extend_layer] += self.layer_block_size
candidates.append(
self._dnn_builder_fn(
num_layers=num_layers,
layer_sizes=new_sizes,
seed=seed,
previous_ensemble=previous_ensemble))
# also check if it's worth adding a new layer
candidates.append(
self._dnn_builder_fn(
num_layers=num_layers + 1,
layer_sizes=layer_sizes + [self.layer_block_size],
seed=seed,
previous_ensemble=previous_ensemble))
# also keep the un-extended candidate
candidates.append(
self._dnn_builder_fn(
num_layers=num_layers,
layer_sizes=layer_sizes,
seed=seed,
previous_ensemble=previous_ensemble))
return candidates
@cweil what do you think?
from adanet.
for t iteration it concat with the previous network ,whether the weight is frozen or not
from adanet.
Related Issues (20)
- `input_fn` called multiple times in `Estimator.train` HOT 5
- relation to AutoML tables in GCP HOT 2
- Question regarding architecture HOT 3
- adanet.ensemble.Ensembler not used in Tutorials? HOT 5
- Adding different loss to tf.estimator.Head HOT 2
- Correct place to add custom metric_fn? HOT 3
- Early stopping 'best-practice' using Adanet
- Interpretation of serialized "architecture_summary" HOT 2
- simple_dnn should not work !
- [Bug] AutoEnsembleEstimator() cannot be instatiated if tf< 2.x HOT 1
- I am having errors and do not know what to do... HOT 1
- Evaluation issue using TPUEstimator HOT 2
- RuntimeError with adanet_tpu tutorial using TF2.2 and Adanet 0.9.0
- AttributeError: module 'adanet' has no attribute 'AutoEnsembleEstimator'
- Is there any code to compute FLOPs and parameter size of adanet?
- Error on running tutorial notebook in Google colab
- Using AdaNet ModelFlow with pre-trained models HOT 1
- Got `AttributeError: 'NoneType' object has no attribute 'logits'` error while applying tutorial
- Is this repository deprecated? HOT 1
- Design suggestions of _IterationBuilder._best_loss from adanet.core.iteration
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adanet.