Class ImageSetUtils

java.lang.Object
deepnetts.util.ImageSetUtils

public class ImageSetUtils extends Object
  • Field Details

  • Constructor Details

    • ImageSetUtils

      public ImageSetUtils()
  • Method Details

    • createDataSetFromRawImages

      public static ImageSet createDataSetFromRawImages(String sourcePath, String targetPath, int targetWidth, int targetHeight, boolean useAbsolutePaths) throws IOException
      Creates image data set from raw images by resizing and randomly croping to target dimensions. Scale image by smaller dimension to target width/height Crop image on center to fit target dimensions Save all images to target path This how its done for AlexNet/ImageNet competition
      Parameters:
      sourcePath -
      targetPath -
      targetWidth -
      targetHeight -
      useAbsolutePaths -
      Returns:
      Throws:
      IOException
    • createRandomlyCroppedImages

      public static void createRandomlyCroppedImages(String srcPath, String destPath, int targetWidth, int targetHeight, int num) throws IOException
      Throws:
      IOException
    • labelsFromSubDirectories

      public static List<String> labelsFromSubDirectories(String path)
      Returns a list of category/class labels from the names of subdirectories for the given path. Use this method to generate labels for example images. Expected directory structure is to have one subdirecotry for each category/class.
      Parameters:
      path - path to search for subirectories
      Returns:
      list of class labels
    • writeToFile

      public static void writeToFile(List<String> list, String fileName) throws IOException
      Writes a given list of strings to file.
      Parameters:
      list - a list of strings to write to file
      fileName - name of the file to write to
      Throws:
      IOException
    • createLabelsIndex

      public static void createLabelsIndex(String path) throws IOException
      Creates a file with list of labels/categories from subdirectories at the specified given path. Labels in file are sorted by name. Names of subdirectories correspond to category/class labels. File is also created at specified path.
      Parameters:
      path - path to directory which contains image categories/classes
      Throws:
      IOException
    • createImageIndex

      public static File createImageIndex(String path) throws IOException
      Creates an index file with list of all files in all subdirectories and write them into single index.txt file. File index.txt is created in specifed path. Expected structure of the directory at given path is path/imageCategoryName/imageFile1.jpg each category of images should have its own directory which is named as corresponding category Sta se desava ako index.txt vec postoji? Da upozorava? Ovaj bi mogao da kreira i indeks labela u jednom cugu Tako korisnik samo napravi direktorijum sa slikama Ovo bi se moglo i automatski pozivati iz image set-a ako nepostoje... ImageSet(Path)
      Parameters:
      path - directory path to index
      Returns:
      created image index file
      Throws:
      IOException
    • balanceUpsample

      public static void balanceUpsample(ImageSet imageSet, Map<String,Integer> clazzStats)
      Balance specified data set by adding random images of each class, to get equal number of examples for each class.
      Parameters:
      imageSet - imageSet to balance
      clazzStats - number of each class
    • balanceDownsample

      public static void balanceDownsample(ImageSet imageSet, Map<String,Integer> clazzStats)
    • renameFilesAsClasses

      public static void renameFilesAsClasses(String srcPath, String className) throws FileNotFoundException
      Renames files in specified directory. New file names correspond to numerated image category/class label. className_0001.jpg, className_002.jpg, ...
      Parameters:
      srcPath -
      className -
      Throws:
      FileNotFoundException
    • createSubSampledImageIndex

      public static File createSubSampledImageIndex(String srcDir, String targetFileName, int samplesPerClass, boolean useFullPath) throws IOException
      Copies specified number of samples of each class from
      Parameters:
      srcDir -
      targetFileName -
      samplesPerClass -
      useFullPath -
      Returns:
      Throws:
      IOException