dataset.py 1.69 KB
Newer Older
Yanhui Liang's avatar
Yanhui Liang committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Prepare dataset for keras model benchmark."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf
21
22
from official.utils.misc import model_helpers  # pylint: disable=g-bad-import-order

Yanhui Liang's avatar
Yanhui Liang committed
23
24
25
26
27
28
29
30
# Default values for dataset.
_NUM_CHANNELS = 3
_NUM_CLASSES = 1000


def _get_default_image_size(model):
  """Provide default image size for each model."""
  image_size = (224, 224)
Yanhui Liang's avatar
Yanhui Liang committed
31
  if model in ["inceptionv3", "xception", "inceptionresnetv2"]:
Yanhui Liang's avatar
Yanhui Liang committed
32
33
34
35
36
37
    image_size = (299, 299)
  elif model in ["nasnetlarge"]:
    image_size = (331, 331)
  return image_size


38
def generate_synthetic_input_dataset(model, batch_size):
Yanhui Liang's avatar
Yanhui Liang committed
39
40
  """Generate synthetic dataset."""
  image_size = _get_default_image_size(model)
41
42
43
  image_shape = (batch_size,) + image_size + (_NUM_CHANNELS,)
  label_shape = (batch_size, _NUM_CLASSES)

Yanhui Liang's avatar
Yanhui Liang committed
44
  dataset = model_helpers.generate_synthetic_data(
45
46
      input_shape=tf.TensorShape(image_shape),
      label_shape=tf.TensorShape(label_shape),
Yanhui Liang's avatar
Yanhui Liang committed
47
48
  )
  return dataset