Skip to content

Commit 9720348

Browse files
committed
Added more to the Usage/ directory
1 parent 15bba11 commit 9720348

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

examples/Usage/DataLoader.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# The pytorchjs DataLoader class
2+
3+
## Background
4+
The DataLoader class allows you to lazy-load data just as you need to pass it to your model for inference. It lets you customise a couple of things:
5+
- The ImageFolder class that you're passing in
6+
- Your batch size
7+
- The transforms that you would like to apply on every image you load

examples/Usage/ImageFolder.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# The pytorchjs ImageFolder class
2+
3+
## Background
4+
The ImageFolder class is an encapsulation of an image (vision) dataset. It lets you do a couple of cool things, including:
5+
- Specify a custom `loader` function to load the image paths passed in. The default for this is a function that loads the image using `numjs`, which is what all our transforms expect :)
6+
- A transform object to be applied per image. This may be overriden if you pass this object into a DataLoader with it's own transform
7+
- `extensions`, a list of acceptable file extensions to load data from. The default array considered is: `[".jpg", ".jpeg", ".png", ".bmp", ".tif", ".tiff"]`
8+
- An `isValidFile` method to check if a file at a given path should be loaded or not.
9+
10+
## Selective Loading
11+
Both `extensions` and the `isValidFile` function may be used to selectively load images from your dataset. Only one of these two parameters may be non-null. A sample isValidFile method that only selects .png images has been specified below.
12+
```js
13+
const customIsValidFile = (targetPath) => targetPath.endsWith(".png")
14+
```

src/torchvision/datasets/ImageFolder.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,18 @@ export class ImageFolder extends DatasetFolder {
1919
* Create a new ImageFolder object
2020
* @param {string} root - The root directory to the target dataset
2121
* @param {Function} [defaultLoader] loader - A custom function used to load images for the ImageFolder
22+
* @param {Array<String>} extensions - A list of valid extensions to load images from
2223
* @param {Transform} [null] transform - A transform/function used to transform source images
2324
* @param {Function} [null] isValidFile - Function to verifty whether a valid file is valid
2425
*/
2526
constructor(
2627
root,
2728
loader = defaultLoader,
29+
extensions = IMAGE_EXTENSIONS,
2830
transform = null,
2931
isValidFile = null
3032
) {
31-
super(
32-
root,
33-
loader,
34-
isValidFile === null ? IMAGE_EXTENSIONS : null,
35-
transform,
36-
isValidFile
37-
);
33+
super(root, loader, extensions, transform, isValidFile);
3834
/**
3935
* A pointer to the Dataset samples
4036
* @type {Array.<{path: String, classIndex: Number }>}

0 commit comments

Comments
 (0)