tensorflow / tensorflow/models

Need to handle mobilenet.py differently in train & eval

Open
#8,918 4 comments 0 reactions 2 assignees View on GitHub

@marksandler2 is already working on this.

Since Jul 22, 2020.

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

Description

Hi,

I found that I need to use two versions of my function in the mobilenet.py to have both train.py & eval.py run properly.
My solution maybe kind of dirty, could you help me understand why are the input parameter distance handled differently run by train.py & eval.py ?

here is my current stable version:

def _apply_dr(input_image, distance, rotation, schrink_ratio_for_distance=2):
    """
    :param distance: an int given by other functions
    :return: rotated & translated featuremap
    """
  with tf.name_scope('apply_dr'):
    image_r = tf.contrib.image.rotate(input_image, angles=-rotation * pi / 180) 

    adjust_distance = - distance / schrink_ratio_for_distance + 0.5

    if not FLAGS.if_training:  # eval
      image_dr = tf.contrib.image.translate(image_r, [adjust_distance, 1])

    else: # training
      distance_xy = tf.concat([adjust_distance, [0.]], 0)
      image_dr = tf.contrib.image.translate(image_r,distance_xy)

    return image_dr

If I swich the line if not FLAGS.if_training: to if FLAGS.if_training: I will get these two errors:

Error for train.py:

ValueError: Shapes must be equal rank, but are 1 and 0
        From merging shape 0 with other shapes. for 'MobilenetV3/combine/apply_dr/translate/translations_to_projective_transforms/translations' (op: 'Pack') with input shapes: [?], [].

Error for eval.py:

ValueError: Can't concatenate scalars (use tf.stack instead) for 'MobilenetV3/combine/apply_dr/concat' (op: 'ConcatV2') with input shapes: [], [1], [].

More Info:

I'm using --model_variant="mobilenet_v3_large_seg" \ on a private dataset.

Main edit is in the research/slim/nets/mobilenet/mobilenet.py, using the _apply_dr in the function mobilenet_base, by separating the for-loop into first n-layers and last 17-n layers.

(distance, rotation) parameters are read from TFrecords, which could be set to (2,1) or (1,2) for debugging.

I am using the pretrained model of cityscapes, which was further trained to fit current dataset, but it has the same parameters-structure.

I ignored the parameter of the first layers's weights in research/deeplab/utils/train_utils.py at Line 211:
exclude_list = ['global_step', , 'MobilenetV3/Conv/weights*']

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.