class_docstr: Activation generator for a basic image model
class_docstr_tok: ["Activation","generator","for","a","basic","image","model"]
docstr: Given a filename, try to open the file.
  
  If failed, return None.
  
  Args:
    filename: location of the image file
    shape: the shape of the image file to be scaled
  
  Returns:
    the image if succeeds, None if fails.
  
  Rasies:
    exception if the image was not the right shape.
docstr_tok: ["Given","a","filename",",","try","to","open","the","file",".","If","failed",",","return","None",".","Args",":","filename",":","location","of","the","image","file","shape",":","the","shape","of","the","image","file","to","be","scaled","Returns",":","the","image","if","succeeds",",","None","if","fails",".","Rasies",":","exception","if","the","image","was","not","the","right","shape","."]
code: def load_image_from_file(self, filename, shape):
      """Given a filename, try to open the file.
  
      If failed, return None.
  
      Args:
        filename: location of the image file
        shape: the shape of the image file to be scaled
  
      Returns:
        the image if succeeds, None if fails.
  
      Rasies:
        exception if the image was not the right shape.
      """
      if not tf.io.gfile.exists(filename):
          tf.compat.v1.logging.error(
              "Cannot find file: {}".format(filename)
          )
          return None
      try:
          # ensure image has no transparency channel
          img = np.array(
              PIL.Image.open(tf.io.gfile.GFile(filename, "rb"))
              .convert("RGB")
              .resize(shape, PIL.Image.BILINEAR),
              dtype=np.float32,
          )
          if self.normalize_image:
              # Normalize pixel values to between 0 and 1.
              img = img / 255.0
          if not (len(img.shape) == 3 and img.shape[2] == 3):
              return None
          else:
              return img
  
      except Exception as e:
          tf.compat.v1.logging.info(e)
          return None
      return img
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from abc import ABCMeta
  from abc import abstractmethod
  from multiprocessing import dummy
  import os
  import os.path
  import numpy
  import PIL.Image
  import six
  import tensorflow
label_desc: Use image node_id 3 for calling the ImageActivationGenerator obj's underlying member method code with example usage: obj.load_image_from_file(filename, shape) and returns: img, None, None, img, None