extract image layers
554653
public void extractDockerImageLayers(File imageTarFile, File imageExtractionDir, Boolean deleteTarFiles) {
        FilesScanner filesScanner = new FilesScanner();
        boolean success = false;
        // docker layers are saved as TAR file (we save it as TAR)
        if (imageTarFile.getName().endsWith(TAR_SUFFIX)) {
            success = unTar(imageTarFile.getName().toLowerCase(), imageExtractionDir.getAbsolutePath(), imageTarFile.getPath());
            boolean deleted = false;
            if (deleteTarFiles) {
                deleted = imageTarFile.delete();
            }
            if (!deleted) {
                logger.warn("Was not able to delete {} (docker image TAR file)", imageTarFile.getName());
            }
        }
        if (success) {
            String[] fileNames = filesScanner.getDirectoryContent(imageExtractionDir.getAbsolutePath(), new String[]{LAYER_TAR}, new String[]{}, true, false);
            for (String filename : fileNames) {
                File layerToExtract = new File(imageExtractionDir + File.separator + filename);
                extractDockerImageLayers(layerToExtract, layerToExtract.getParentFile(), deleteTarFiles);
            }
        } else {
            logger.warn("Was not able to extract {} (docker image TAR file)", imageTarFile.getName());
        }
    }
1260625
def layers(self):
        '''
        '''

        layermap = dict()
        for operator in self.ops:
            if hasattr(operator, 'layers'):
                layermap.update(operator.layers())
        return layermap
726546
def extract_feature(self, image, layer):
        

        img = image.astype(np.float32)
        # Substracting Image mean value
        img -= np.array((104.00698793, 116.66876762, 122.67891434))

        # make dims C x H x W for Caffe
        img = img.transpose((2, 0, 1))
        in_img = img[np.newaxis, :, :, :]

        self.net.blobs['data'].reshape(*in_img.shape)

        data_feat = self.net.forward_all(data=in_img, blobs=[layer])

        feature = data_feat[layer][0]

        # feature = (feature - feature.mean()) / feature.std()
        # feature /= np.linalg.norm(feature)
        return feature
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
631225
def extract_images_generic(pike, root, log, options):
    """"""

    jpegs = []
    pngs = []
    for _, xref, ext in extract_images(pike, root, log, options, extract_image_generic):
        log.debug('xref = %s ext = %s', xref, ext)
        if ext == '.png':
            pngs.append(xref)
        elif ext == '.jpg':
            jpegs.append(xref)
    log.debug("Optimizable images: JPEGs: %s PNGs: %s", len(jpegs), len(pngs))
    return jpegs, pngs
806015
def layered(self, images, only_pushable=False):
        """"""
        if only_pushable:
            operate_on = dict((image, instance) for image, instance in images.items() if instance.image_index)
        else:
            operate_on = images

        layers = Layers(operate_on, all_images=images)
        layers.add_all_to_layers()
        for layer in layers.layered:
            buf = []
            for image_name, image in layer:
                if image.image_index:
                    buf.append((image_name, image))
            if buf:
                yield buf
425507
def get_layers(proto):
    
    if len(proto.layer):
        return proto.layer
    elif len(proto.layers):
        return proto.layers
    else:
        raise ValueError('Invalid proto file.')
483379
def _extract_blocks(x, block_h, block_w):
  
  (_, height, width, depth) = common_layers.shape_list(x)
  assert height % block_h == 0
  assert width % block_w == 0
  x = tf.reshape(x, [-1, height//block_h, block_h,
                     width//block_w, block_w, depth])
  return tf.transpose(x, [0, 1, 3, 2, 4, 5])
363779
def _image_gradients(self, input_csvlines, label, image_column_name):
        """"""

        with tf.Graph().as_default() as g, tf.Session() as sess:
            logging_level = tf.logging.get_verbosity()
            try:
                tf.logging.set_verbosity(tf.logging.ERROR)
                meta_graph_pb = tf.saved_model.loader.load(
                    sess=sess,
                    tags=[tf.saved_model.tag_constants.SERVING],
                    export_dir=self._model_dir)
            finally:
                tf.logging.set_verbosity(logging_level)

            signature = meta_graph_pb.signature_def['serving_default']
            input_alias_map = {name: tensor_info_proto.name
                               for (name, tensor_info_proto) in signature.inputs.items()}
            output_alias_map = {name: tensor_info_proto.name
                                for (name, tensor_info_proto) in signature.outputs.items()}

            csv_tensor_name = list(input_alias_map.values())[0]

            # The image tensor is already built into ML Workbench graph.
            float_image = g.get_tensor_by_name("import/gradients_%s:0" % image_column_name)
            if label not in output_alias_map:
                raise ValueError('The label "%s" does not exist in output map.' % label)

            prob = g.get_tensor_by_name(output_alias_map[label])
            grads = tf.gradients(prob, float_image)[0]
            grads_values = sess.run(fetches=grads, feed_dict={csv_tensor_name: input_csvlines})

        return grads_values
1363239
def put_image_layer(self, image_id, data):
        """"""
        return self._http_call(self.IMAGE_JSON, put,
                               data=data, image_id=image_id)
524704
def layers():
  """"""
  global _cached_layers
  if _cached_layers is not None:
    return _cached_layers
  layers_module = tf.layers
  try:
    from tensorflow.python import tf2  # pylint: disable=g-direct-tensorflow-import,g-import-not-at-top
    if tf2.enabled():
      tf.logging.info("Running in V2 mode, using Keras layers.")
      layers_module = tf.keras.layers
  except ImportError:
    pass
  _cached_layers = layers_module
  return layers_module
755749
def _collect_layer_outputs(mod, data, include_layer=None, max_num_examples=None, logger=None):
    """"""
    collector = _LayerOutputCollector(include_layer=include_layer, logger=logger)
    num_examples = _collect_layer_statistics(mod, data, collector, max_num_examples, logger)
    return collector.nd_dict, num_examples
341993
def get_layers(self, class_: Type[L], became: bool=True) -> List[L]:
        

        out = self._index.get(class_, [])

        if became:
            out += self._transformed.get(class_, [])

        return out
467473
private void extractFgBgData(Map<Integer, Integer> colorHistogram) {
        if (colorHistogram.isEmpty()) {
            // An empty histogram indicates we've encountered a 0px area image. It has no luminance.
            mBackgroundLuminance = mForegroundLuminance = 0;
            mBackgroundColor = Color.BLACK;
            mForegroundColor = Color.BLACK;
        } else if (colorHistogram.size() == 1) {
            // Deal with views that only contain a single color
            final int singleColor = colorHistogram.keySet().iterator().next();
            mBackgroundLuminance = mForegroundLuminance =
                    ContrastUtils.calculateLuminance(singleColor);
            mForegroundColor = singleColor;
            mBackgroundColor = singleColor;
        } else {
            // Find the average luminance value within the set of luminances for
            // purposes of splitting luminance values into high-luminance and
            // low-luminance buckets. This is explicitly not a weighted average.
            double luminanceSum = 0;
            for (int color : colorHistogram.keySet()) {
                luminanceSum += ContrastUtils.calculateLuminance(color);
            }

            final double averageLuminance = luminanceSum / colorHistogram.size();

            // Select the highest and lowest luminance values that contribute to
            // most number of pixels in the image -- our background and
            // foreground colors.
            double lowLuminanceContributor = 0.0d;
            double highLuminanceContributor = 1.0d;
            int lowLuminanceColor = -1;
            int highLuminanceColor = -1;
            int maxLowLuminanceFrequency = 0;
            int maxHighLuminanceFrequency = 0;
            for (Entry<Integer, Integer> entry : colorHistogram.entrySet()) {
                final int color = entry.getKey();
                final double luminanceValue = ContrastUtils.calculateLuminance(color);
                final int frequency = entry.getValue();
                if ((luminanceValue < averageLuminance) && (frequency > maxLowLuminanceFrequency)) {
                    lowLuminanceContributor = luminanceValue;
                    maxLowLuminanceFrequency = frequency;
                    lowLuminanceColor = color;
                } else if ((luminanceValue >= averageLuminance)
                        && (frequency > maxHighLuminanceFrequency)) {
                    highLuminanceContributor = luminanceValue;
                    maxHighLuminanceFrequency = frequency;
                    highLuminanceColor = color;
                }
            }

            // Background luminance is that which occurs more frequently
            if (maxHighLuminanceFrequency > maxLowLuminanceFrequency) {
                mBackgroundLuminance = highLuminanceContributor;
                mBackgroundColor = highLuminanceColor;
                mForegroundLuminance = lowLuminanceContributor;
                mForegroundColor = lowLuminanceColor;
            } else {
                mBackgroundLuminance = lowLuminanceContributor;
                mBackgroundColor = lowLuminanceColor;
                mForegroundLuminance = highLuminanceContributor;
                mForegroundColor = highLuminanceColor;
            }
        }
    }
30636
function extractFaces(volume) {
  var result = []
  var normals = []

  //For each axis, extract all facets
  for(var d=0; d<3; ++d) {
    var u = (d+1) % 3
    var v = (d+2) % 3

    var normal = [0,0,0]

    var n = volume.shape[d]
    var m = volume.shape[u]
    var l = volume.shape[v]

    var x = ndarray(new Uint8Array(m * l), [m, l])
    
    for(var i=1; i<n-1; ++i) {
      var slice0, slice1, slice2
      if(d === 0) {
        slice0 = volume.pick(i-1)
        slice1 = volume.pick(i)
        slice2 = volume.pick(i+1)
      } else if(d === 1) {
        slice0 = volume.pick(-1, i-1).transpose(1,0)
        slice1 = volume.pick(-1, i).transpose(1,0)
        slice2 = volume.pick(-1, i+1).transpose(1,0)
      } else if(d === 2) {
        slice0 = volume.pick(-1, -1, i-1)
        slice1 = volume.pick(-1, -1, i)
        slice2 = volume.pick(-1, -1, i+1)
      }

      normal[d] = -1
      for(var s=0; s<m; ++s) {
        for(var t=0; t<l; ++t) {
          x.set(s, t, !!slice1.get(s,t) && !slice0.get(s,t))
        }
      }
      var f = contour(x, slice0)
      for(var j=0; j<f.length; ++j) {
        result.push(f[j].map(function(p) {
          var y = [i,i,i]
          y[u] = p[1]
          y[v] = p[0]
          return y
        }))
        normals.push(normal.slice())
      }

      normal[d] = 1
      for(var s=0; s<m; ++s) {
        for(var t=0; t<l; ++t) {
          x.set(s, t, !!slice1.get(s,t) && !slice2.get(s,t))
        }
      }
      var f = contour(x, slice2)
      for(var j=0; j<f.length; ++j) {
        f[j].reverse()
        result.push(f[j].map(function(p) {
          var y = [i+1,i+1,i+1]
          y[u] = p[1]
          y[v] = p[0]
          return y
        }))
        normals.push(normal.slice())
      }
    }
  }

  return [result, normals]
}
1291262
def map_images_in_tex(tex_files, image_mapping,
                      output_directory, context=False):
    """"""
    extracted_image_data = []
    for tex_file in tex_files:
        # Extract images, captions and labels based on tex file and images
        partly_extracted_image_data = extract_captions(
            tex_file,
            output_directory,
            image_mapping.keys()
        )
        if partly_extracted_image_data:
            # Convert to dict, add proper filepaths and do various cleaning
            cleaned_image_data = prepare_image_data(
                partly_extracted_image_data,
                output_directory,
                image_mapping,
            )
            if context:
                # Using prev. extracted info, get contexts for each image found
                extract_context(tex_file, cleaned_image_data)

            extracted_image_data.extend(cleaned_image_data)

    return extracted_image_data
1233606
def layers(self):
        
        # sample output:
        # {
        #     "Created": 1457116802,
        #     "Id": "sha256:507cb13a216097710f0d234668bf64a4c92949c573ba15eba13d05aad392fe04",
        #     "Size": 204692029,
        #     "Tags": [
        #         "docker.io/fedora:latest"
        #     ],
        #     "Comment": "",
        #     "CreatedBy": "/bin/sh -c #(nop) ADD file:bcb5e5c... in /"
        # }
        try:
            response = self.d.history(self.image_id)
        except docker.errors.NotFound:
            raise NotAvailableAnymore()

        layers = []
        for l in response:
            layer_id = l["Id"]
            if layer_id == "<missing>":
                layers.append(DockerImage(l, self.docker_backend))
            else:
                layers.append(self.docker_backend.get_image_by_id(layer_id))
        return layers