Coder Social home page Coder Social logo

generate_images's Introduction

Generate Images

Estimator: TF-GAN's GANEstimator

Data: CIFAR dataset

Processor: Google Cloud TPU

Objective: To create a Generative Adverserial Network for generating fake images.

Notebook

Study reference

generate_images's People

Contributors

likarajo avatar

Watchers

 avatar  avatar

generate_images's Issues

InvalidArgumentError: 'object' must be a non-empty string. (File: gs://likarajo_bucket/)

dataset_dir = 'gs://{}/{}'.format(bucket, 'datasets')

def input_fn(mode, params):
  assert 'batch_size' in params
  assert 'noise_dims' in params
  bs = params['batch_size']
  nd = params['noise_dims']
  split = 'train' if mode == tf.estimator.ModeKeys.TRAIN else 'test'
  shuffle = (mode == tf.estimator.ModeKeys.TRAIN)
  just_noise = (mode == tf.estimator.ModeKeys.PREDICT)
  
  noise_ds = (tf.data.Dataset.from_tensors(0)
              .map(lambda _: tf.random_normal([bs, nd]))
              # If 'predict', just generate one batch.
              .repeat(1 if just_noise else None))
  
  if just_noise:
    return noise_ds

  def _preprocess(element):
    # Map [0, 255] to [-1, 1].
    images = (tf.cast(element['image'], tf.float32) - 127.5) / 127.5
    return images

  images_ds = (tfds.load('cifar10:3.*.*', split=split, data_dir=dataset_dir)
               .map(_preprocess, num_parallel_calls=4)
               .cache()
               .repeat())
  if shuffle:
    images_ds = images_ds.shuffle(
        buffer_size=10000, reshuffle_each_iteration=True)
  images_ds = (images_ds.batch(bs, drop_remainder=True)
               .prefetch(tf.data.experimental.AUTOTUNE))

  return tf.data.Dataset.zip((noise_ds, images_ds))
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-16-0e87204247b4> in <module>()
      1 params = {'batch_size': 1, 'noise_dims':1}
----> 2 input_fn(tf.estimator.ModeKeys.EVAL, params)

5 frames
<ipython-input-15-ec8f86310b3d> in input_fn(mode, params)
     26     return images
     27 
---> 28   images_ds = (tfds.load('cifar10:3.*.*', split=split, data_dir=dataset_dir)
     29                .map(_preprocess, num_parallel_calls=4)
     30                .cache()

/usr/local/lib/python3.6/dist-packages/tensorflow_datasets/core/load.py in load(name, split, data_dir, batch_size, shuffle_files, download, as_supervised, decoders, read_config, with_info, builder_kwargs, download_and_prepare_kwargs, as_dataset_kwargs, try_gcs)
    342   if download:
    343     download_and_prepare_kwargs = download_and_prepare_kwargs or {}
--> 344     dbuilder.download_and_prepare(**download_and_prepare_kwargs)
    345 
    346   if as_dataset_kwargs is None:

/usr/local/lib/python3.6/dist-packages/tensorflow_datasets/core/dataset_builder.py in download_and_prepare(self, download_dir, download_config)
    370     dl_manager = self._make_download_manager(
    371         download_dir=download_dir,
--> 372         download_config=download_config)
    373 
    374     # Create a tmp dir and rename to self._data_dir on successful exit.

/usr/local/lib/python3.6/dist-packages/tensorflow_datasets/core/dataset_builder.py in _make_download_manager(self, download_dir, download_config)
    796         force_extraction=(download_config.download_mode == FORCE_REDOWNLOAD),
    797         force_checksums_validation=download_config.force_checksums_validation,
--> 798         register_checksums=download_config.register_checksums,
    799     )
    800 

/usr/local/lib/python3.6/dist-packages/tensorflow_datasets/core/download/download_manager.py in __init__(self, download_dir, extract_dir, manual_dir, manual_dir_instructions, url_infos, dataset_name, force_download, force_extraction, force_checksums_validation, register_checksums)
    201     self._manual_dir = manual_dir and os.path.expanduser(manual_dir)
    202     self._manual_dir_instructions = manual_dir_instructions
--> 203     tf.io.gfile.makedirs(self._download_dir)
    204     tf.io.gfile.makedirs(self._extract_dir)
    205     self._force_download = force_download

/usr/local/lib/python3.6/dist-packages/tensorflow/python/lib/io/file_io.py in recursive_create_dir_v2(path)
    481     errors.OpError: If the operation fails.
    482   """
--> 483   _pywrap_file_io.RecursivelyCreateDir(compat.path_to_bytes(path))
    484 
    485 

InvalidArgumentError: 'object' must be a non-empty string. (File: gs://likarajo_bucket/)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.