Package deepnetts.util
Class ImageSetUtils
java.lang.Object
deepnetts.util.ImageSetUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
balanceDownsample
(ImageSet imageSet, Map<String, Integer> clazzStats) 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.static ImageSet
createDataSetFromRawImages
(String sourcePath, String targetPath, int targetWidth, int targetHeight, boolean useAbsolutePaths) Creates image data set from raw images by resizing and randomly croping to target dimensions.static File
createImageIndex
(String path) Creates an index file with list of all files in all subdirectories and write them into single index.txt file.static void
createLabelsIndex
(String path) Creates a file with list of labels/categories from subdirectories at the specified given path.static void
createRandomlyCroppedImages
(String srcPath, String destPath, int targetWidth, int targetHeight, int num) static File
createSubSampledImageIndex
(String srcDir, String targetFileName, int samplesPerClass, boolean useFullPath) Copies specified number of samples of each class fromReturns a list of category/class labels from the names of subdirectories for the given path.static void
renameFilesAsClasses
(String srcPath, String className) Renames files in specified directory.static void
writeToFile
(List<String> list, String fileName) Writes a given list of strings to file.
-
Field Details
-
LABELS_FILE
- See Also:
-
TRAIN_FILE
- See Also:
-
TEST_FILE
- See Also:
-
IMAGE_IDX_FILE
- See Also:
-
-
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
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
Writes a given list of strings to file.- Parameters:
list
- a list of strings to write to filefileName
- name of the file to write to- Throws:
IOException
-
createLabelsIndex
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
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
-
balanceDownsample
-
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
-