tensorflow / tensorflow/models

how to reuse Variables if I am adding node to the graph of deeplab?

Open
#8,897 1 comment 0 reactions 3 assignees View on GitHub

@aquariusjay is already working on this.

Since Jul 17, 2020.

models:research type:support
Dominant language
Python
Stars
77.7k
Forks
44.8k
PR merge metrics
No merged PRs in 30d

Description

Also regarding the modification: since you are creating a the first layer (which outputs feature_2) under different variable scope, my bet is it would not be shared with the layer that creates feature_1 ;)

Originally posted by @YknZhu in https://github.com/tensorflow/models/issues/8864#issuecomment-659563101


Hi,

I want to reuse some layers of the pre-defined mobilenet-v3 backbone, so I made some modification in research/slim/nets/mobilenet/mobilenet.py

basically like this:

with tf.variable_scope('parallel_layer',reuse=tf.compat.v1.AUTO_REUSE) as scope:
   try:
        net1 = opdef.op(net1, **params)
        net2 = opdef.op(net2, **params)
   except Exception:
        print('Failed to create op %i: %r params: %r' % (i, opdef, params))

Ps. I also tried without the extra variable_scope. I.e. "MobilenetV3" instead of "MobilenetV3/parallel_layer".

According to the graph in tensorboard, I do have two nodes (Conv & Conv_1) instead of only one node (Conv) now. I can't load pre-trained checkpoint anyway since the graph was changed.

How to reuse the layers correctly? And how to know weather I am correct?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.