Extract the VQA V2 image data set to directory unless it's there.
176764
def _get_vqa_v2_image_raw_dataset(directory, image_root_url, image_urls):
  """"""
  for url in image_urls:
    filename = os.path.basename(url)
    download_url = os.path.join(image_root_url, url)
    path = generator_utils.maybe_download(directory, filename, download_url)
    unzip_dir = os.path.join(directory, filename.strip(".zip"))
    if not tf.gfile.Exists(unzip_dir):
      zipfile.ZipFile(path, "r").extractall(directory)
885604
def maybe_download_image_dataset(image_ids, target_dir):
  

  tf.gfile.MakeDirs(target_dir)

  num_images = len(image_ids)

  for i, image_id in enumerate(image_ids):

    destination = os.path.join(target_dir, "%s.jpg" % i)
    tmp_destination = "%s.temp" % destination

    source_url = ("http://api.brain-map.org/api/v2/"
                  "section_image_download/%s" % image_id)

    if tf.gfile.Exists(destination):
      tf.logging.info("Image with ID already present, "
                      "skipping download (%s of %s)." % (
                          i+1, num_images
                      ))
      continue

    tf.logging.info("Downloading image with id %s (%s of %s)" % (
        image_id, i+1, num_images
    ))

    response = requests.get(source_url, stream=True)

    response.raise_for_status()

    with tf.gfile.Open(tmp_destination, "w") as f:
      for block in response.iter_content(1024):
        f.write(block)

    tf.gfile.Rename(tmp_destination, destination)
169278
def get_wd_data2(self):
        
        wait = wx.BusyInfo('Reading in data from current working directory, please wait...')
        #wx.Yield()
        print('-I- Read in any available data from working directory (data model 2)')

        self.er_magic = builder.ErMagicBuilder(self.WD,
                                               data_model=self.data_model)
        del wait
1235126
private static void extractImageData(@NotNull final EpsDirectory directory, String imageData) throws IOException
    {
        // %ImageData: 1000 1000 8 3 1 1000 7 "beginimage"
        directory.setString(EpsDirectory.TAG_IMAGE_DATA, imageData.trim());

        String[] imageDataParts = imageData.split(" ");

        int width = Integer.parseInt(imageDataParts[0]);
        int height = Integer.parseInt(imageDataParts[1]);
        int colorType = Integer.parseInt(imageDataParts[3]);

        // Only add values that are not already present
        if (!directory.containsTag(EpsDirectory.TAG_IMAGE_WIDTH))
            directory.setInt(EpsDirectory.TAG_IMAGE_WIDTH, width);
        if (!directory.containsTag(EpsDirectory.TAG_IMAGE_HEIGHT))
            directory.setInt(EpsDirectory.TAG_IMAGE_HEIGHT, height);
        if (!directory.containsTag(EpsDirectory.TAG_COLOR_TYPE))
            directory.setInt(EpsDirectory.TAG_COLOR_TYPE, colorType);

        if (!directory.containsTag(EpsDirectory.TAG_RAM_SIZE)) {
            int bytesPerPixel = 0;
            if (colorType == 1)
                bytesPerPixel = 1; // grayscale
            else if (colorType == 2 || colorType == 3)
                bytesPerPixel = 3; // Lab or RGB
            else if (colorType == 4)
                bytesPerPixel = 3; // CMYK

            if (bytesPerPixel != 0)
                directory.setInt(EpsDirectory.TAG_RAM_SIZE, bytesPerPixel * width * height);
        }
    }
993742
def get_image_path(definition):
    
    path = resources_path(
        'img', 'wizard', 'keyword-subcategory-%s.svg' % definition['key'])
    if os.path.exists(path):
        return path
    else:
        return not_set_image_path
44276
def get_qpimage_raw(self, idx=0):
        """"""
        qpi = qpimage.QPImage(h5file=self.path,
                              h5mode="r",
                              h5dtype=self.as_type,
                              ).copy()
        # Remove previously performed background correction
        qpi.set_bg_data(None)
        # Force meta data
        for key in self.meta_data:
            qpi[key] = self.meta_data[key]
        # set identifier
        qpi["identifier"] = self.get_identifier(idx)
        return qpi
96720
def ensure_image(name, url, images_root, md5, untar_to=None):
    """"""
    image_dir_path = os.path.join(images_root, name)
    mkdir(image_dir_path)
    image_file_path = os.path.join(image_dir_path, os.path.basename(url))
    ensure_file(url, image_file_path, md5)
    if untar_to:
        prepare_image(image_file_path, untar_to)
321468
def _get_path(dataset_name):
  """"""
  path = _checksum_paths().get(dataset_name, None)
  if path:
    return path
  msg = ('No checksums file could be find for dataset %s. Please create one in '
         'one of: %s') % (dataset_name, ', '.join(_CHECKSUM_DIRS))
  raise AssertionError(msg)
1183063
def _getProcessedImage(self):
        """"""
        if self.imageDisp is None:
            self.imageDisp = self.image
            self.levelMin, self.levelMax = self._quickLevels(
                self.imageDisp)
            #list( map(float, self._quickLevels(self.imageDisp)))
        return self.imageDisp
540287
def get(img, cache_dir=CACHE_DIR, iterative=False):
    """"""
    if os.path.isfile(img):
        wal_img = img

    elif os.path.isdir(img):
        if iterative:
            wal_img = get_next_image(img)

        else:
            wal_img = get_random_image(img)

    else:
        logging.error("No valid image file found.")
        sys.exit(1)

    wal_img = os.path.abspath(wal_img)

    # Cache the image file path.
    util.save_file(wal_img, os.path.join(cache_dir, "wal"))

    logging.info("Using image \033[1;37m%s\033[0m.", os.path.basename(wal_img))
    return wal_img
58327
def get_next_image(img_dir):
    """"""
    images, current_wall = get_image_dir(img_dir)
    images.sort(key=lambda img: [int(x) if x.isdigit() else x
                                 for x in re.split('([0-9]+)', img)])

    try:
        next_index = images.index(current_wall) + 1

    except ValueError:
        next_index = 0

    try:
        image = images[next_index]

    except IndexError:
        image = images[0]

    return os.path.join(img_dir, image)
290807
def extract_chm (archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    # archmage can only extract in non-existing directories
    # so a nice dirname is created
    name = util.get_single_outfile("", archive)
    outfile = os.path.join(outdir, name)
    return [cmd, '-x', os.path.abspath(archive), outfile]
1183602
def get_image(verbose=False):
  """"""
  base_data = tf.constant(image_data(verbose=verbose))
  base_image = tf.image.decode_image(base_data, channels=3)
  base_image.set_shape((IMAGE_HEIGHT, IMAGE_WIDTH, 3))
  parsed_image = tf.Variable(base_image, name='image', dtype=tf.uint8)
  return parsed_image
826513
def extract_lzma(archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    return _extract(archive, compression, cmd, 'alone', verbosity, outdir)
242711
def extract_archive(archive_path, destination_path):
    """"""
    tar = tarfile.open(archive_path)
    tar.errorlevel = 1
    tar.extractall(destination_path)
181273
def cache_image_data(cache_dir, cache_key, uploader, *args, **kwargs):
    
    use_cache = True
    if "use_cache" in kwargs:
        use_cache = kwargs["use_cache"]
        del kwargs["use_cache"]

    json_path = None
    if cache_dir:
        json_path = os.path.join(cache_dir, "cached-img-%s.json" % cache_key)
        if use_cache and os.path.exists(json_path):
            LOG.info("Fetching %r from cache..." % (args,))
            try:
                with closing(open(json_path, "r")) as handle:
                    img_data = json.load(handle)

                return parts.Bunch([(key, parts.Bunch(val))
                    for key, val in img_data.items() # BOGUS pylint: disable=E1103
                ])
            except (EnvironmentError, TypeError, ValueError) as exc:
                LOG.warn("Problem reading cached data from '%s', ignoring cache... (%s)" % (json_path, exc))

    LOG.info("Copying %r..." % (args,))
    img_data = uploader(*args, **kwargs)

    if json_path:
        with closing(open(json_path, "w")) as handle:
            json.dump(img_data, handle)

    return img_data
144709
def extract_data(filename, num_images):
  
  print('Extracting', filename)
  with gzip.open(filename) as bytestream:
    bytestream.read(16)
    buf = bytestream.read(IMAGE_SIZE * IMAGE_SIZE * num_images)
    data = np.frombuffer(buf, dtype=np.uint8).astype(np.float32)
    data = (data - (PIXEL_DEPTH / 2.0)) / PIXEL_DEPTH
    data = data.reshape(num_images, IMAGE_SIZE, IMAGE_SIZE, 1)
    return data