bdlb/diabetic_retinopathy_diagnosis/tfds_adapter.py
def _generate_examples(self, images_dir_path, csv_path=None, csv_usage=None):
    """Yields Example instances from given CSV. Applies contrast enhancement as
    in https://github.com/btgraham/SparseConvNet/tree/kaggle_Diabetic_Retinopat
    hy_competition. Turns the multiclass (i.e. 5 classes) problem to binary
    classification according to
    https://www.nature.com/articles/s41598-017-17876-z.pdf.

    Args:
      images_dir_path: path to dir in which images are stored.
      csv_path: optional, path to csv file with two columns: name of image and
        label. If not provided, just scan image directory, don't set labels.
      csv_usage: optional, subset of examples from the csv file to use based on
        the "Usage" column from the csv.
    """
    if csv_path:
      with tf.io.gfile.GFile(csv_path) as csv_f:
        reader = csv.DictReader(csv_f)
        data = [(row["image"], int(row["level"]))
                for row in reader
                if csv_usage is None or row["Usage"] == csv_usage]
    else:
      data = [(fname[:-5], -1)
              for fname in tf.io.gfile.listdir(images_dir_path)
              if fname.endswith(".jpeg")]
    for name, label in data:
      record = {
          "name":
              name,
          "image":
              self._preprocess(
                  tf.io.gfile.GFile("%s/%s.jpeg" % (images_dir_path, name),
                                    mode="rb"),
                  target_height=self.builder_config.target_height,
                  target_width=self.builder_config.target_width,
              ),
          "label":
              int(label > 1),
      }

      yield record
Yields Example instances from given CSV. Applies contrast enhancement as
    in https://github.com/btgraham/SparseConvNet/tree/kaggle_Diabetic_Retinopat
    hy_competition. Turns the multiclass (i.e. 5 classes) problem to binary
    classification according to
    https://www.nature.com/articles/s41598-017-17876-z.pdf.

    Args:
      images_dir_path: path to dir in which images are stored.
      csv_path: optional, path to csv file with two columns: name of image and
        label. If not provided, just scan image directory, don't set labels.
      csv_usage: optional, subset of examples from the csv file to use based on
        the "Usage" column from the csv.
    
Yields Example instances from given CSV.
Yields Example instances from given CSV .
def _generate_examples(self, images_dir_path, csv_path=None, csv_usage=None):
    if csv_path:
      with tf.io.gfile.GFile(csv_path) as csv_f:
        reader = csv.DictReader(csv_f)
        data = [(row["image"], int(row["level"]))
                for row in reader
                if csv_usage is None or row["Usage"] == csv_usage]
    else:
      data = [(fname[:-5], -1)
              for fname in tf.io.gfile.listdir(images_dir_path)
              if fname.endswith(".jpeg")]
    for name, label in data:
      record = {
          "name":
              name,
          "image":
              self._preprocess(
                  tf.io.gfile.GFile("%s/%s.jpeg" % (images_dir_path, name),
                                    mode="rb"),
                  target_height=self.builder_config.target_height,
                  target_width=self.builder_config.target_width,
              ),
          "label":
              int(label > 1),
      }
      yield record
def _generate_examples ( self , images_dir_path , csv_path = None , csv_usage = None ) : if csv_path : with tf . io . gfile . GFile ( csv_path ) as csv_f : reader = csv . DictReader ( csv_f ) data = [ ( row [ "image" ] , int ( row [ "level" ] ) ) for row in reader if csv_usage is None or row [ "Usage" ] == csv_usage ] else : data = [ ( fname [ : - 5 ] , - 1 ) for fname in tf . io . gfile . listdir ( images_dir_path ) if fname . endswith ( ".jpeg" ) ] for name , label in data : record = { "name" : name , "image" : self . _preprocess ( tf . io . gfile . GFile ( "%s/%s.jpeg" % ( images_dir_path , name ) , mode = "rb" ) , target_height = self . builder_config . target_height , target_width = self . builder_config . target_width , ) , "label" : int ( label > 1 ) , } yield record
Yields Example instances from given CSV.
Yields Example instances from given CSV .
"""Yields Example instances from given CSV. Applies contrast enhancement as
    in https://github.com/btgraham/SparseConvNet/tree/kaggle_Diabetic_Retinopat
    hy_competition. Turns the multiclass (i.e. 5 classes) problem to binary
    classification according to
    https://www.nature.com/articles/s41598-017-17876-z.pdf.

    Args:
      images_dir_path: path to dir in which images are stored.
      csv_path: optional, path to csv file with two columns: name of image and
        label. If not provided, just scan image directory, don't set labels.
      csv_usage: optional, subset of examples from the csv file to use based on
        the "Usage" column from the csv.
    """
self
images_dir_path
path to dir in which images are stored.
path to dir in which images are stored .
csv_path
optional, path to csv file with two columns: name of image and
label. If not provided, just scan image directory, don't set labels.
optional path to csv file with two columns : name of image and label . If not provided just scan image directory don ' t set labels .
csv_usage
optional, subset of examples from the csv file to use based on
the "Usage" column from the csv.
optional subset of examples from the csv file to use based on the " Usage " column from the csv .