-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring of the preprocessing DSL (#416) #425
Conversation
Wouldn't it be sufficient to just generify |
dataset/src/jvmMain/kotlin/org/jetbrains/kotlinx/dl/dataset/preprocessor/image/CenterCrop.kt
Outdated
Show resolved
Hide resolved
dataset/src/commonMain/kotlin/org/jetbrains/kotlinx/dl/dataset/preprocessing/Preprocessor.kt
Outdated
Show resolved
Hide resolved
dataset/src/commonMain/kotlin/org/jetbrains/kotlinx/dl/dataset/preprocessing/Preprocessor.kt
Outdated
Show resolved
Hide resolved
dataset/src/jvmMain/kotlin/org/jetbrains/kotlinx/dl/dataset/preprocessor/Preprocessing.kt
Outdated
Show resolved
Hide resolved
dataset/src/jvmMain/kotlin/org/jetbrains/kotlinx/dl/dataset/preprocessor/Preprocessing.kt
Outdated
Show resolved
Hide resolved
dataset/src/jvmMain/kotlin/org/jetbrains/kotlinx/dl/dataset/preprocessor/Preprocessing.kt
Outdated
Show resolved
Hide resolved
dataset/src/jvmMain/kotlin/org/jetbrains/kotlinx/dl/dataset/preprocessor/Preprocessing.kt
Outdated
Show resolved
Hide resolved
dataset/src/androidMain/kotlin/org/jetbrains/kotlinx/dl/dataset/preprocessing/Preprocessing.kt
Outdated
Show resolved
Hide resolved
Something like this: master...juliabeliaeva:wip/preprocessing-api |
Would have been better to have separate PR for android implementation. |
We definitely should include more explanation of the changes into the resulting commit message, since we are basically having a new DSL here. Also let's mention in the message that we moved from |
...src/androidMain/kotlin/org/jetbrains/kotlinx/dl/dataset/preprocessing/ConvertToFloatArray.kt
Outdated
Show resolved
Hide resolved
...src/androidMain/kotlin/org/jetbrains/kotlinx/dl/dataset/preprocessing/ConvertToFloatArray.kt
Outdated
Show resolved
Hide resolved
...src/androidMain/kotlin/org/jetbrains/kotlinx/dl/dataset/preprocessing/ConvertToFloatArray.kt
Outdated
Show resolved
Hide resolved
) | ||
imgData.rewind() | ||
val stride = input.width * input.height | ||
val bmpData = IntArray(stride.toInt()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't stride
already Int
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix it in separate PR with operations for an Android platform
...kotlin/examples/transferlearning/modelhub/vgg16/Example_5_VGG16_additional_training_noTop.kt
Outdated
Show resolved
Hide resolved
onnx/src/jvmMain/kotlin/org/jetbrains/kotlinx/dl/api/dataset/preprocessor/Transpose.kt
Outdated
Show resolved
Hide resolved
onnx/src/jvmMain/kotlin/org/jetbrains/kotlinx/dl/api/dataset/preprocessor/Transpose.kt
Show resolved
Hide resolved
tensorflow/src/main/kotlin/org/jetbrains/kotlinx/dl/dataset/preprocessor/Sharpen.kt
Show resolved
Hide resolved
...src/jvmMain/kotlin/org/jetbrains/kotlinx/dl/dataset/preprocessor/image/ImageOperationBase.kt
Outdated
Show resolved
Hide resolved
Let's add tests for the android operations and for new |
dataset/src/jvmMain/kotlin/org/jetbrains/kotlinx/dl/dataset/preprocessor/image/Convert.kt
Outdated
Show resolved
Hide resolved
...rc/commonMain/kotlin/org/jetbrains/kotlinx/dl/dataset/preprocessing/PreprocessingPipeline.kt
Outdated
Show resolved
Hide resolved
New preprocessing API implies that preprocessing operations are defined as functional objects with Input and Output types defined as generics. Operations can be composed together to form a pipeline. The output of the operation is the input of the next operation. At the end of the pipeline, the output of the last operation is the pipeline's output. The approach when the pipeline is defined as a sequence of operations has the following advantages: - it's more flexible and supports the composition of operations with different input and output types. - user explicitly specifies conversions between types during the pipeline definition. E.g. there is an Operation that converts from [BufferedImage] to [FloatArray]. - allows adding support of augmentations in the future without changing the API. * Remove imagePreprocessing and tensorPreprocessing DSL blocks * User explicitly convert BufferedImage to FloatArray * Replace ImageShape with TensorShape * getOutputShape method now implemented for tensor operations and now calculates correct shape for operations such as Transpose * Update tests and examples with new API Co-authored-by: Julia Beliaeva <Julia.Beliaeva@jetbrains.com>
* Now method takes requested color mode into account when computing output shape * Add tests for output shape calculation
* Add support for unknown dimension in input TensorShape * Add BufferedImage.getTensorShape extension function
* Dimensions that are -1 in TensorShape are converted to null in ImageShape.
* Remove useless toInt casts * Fix ImageProessing example * Remove commented code
* Fix output shape calculation for Transpose operation * Add test for an output shape calculation
* Add FloatArrayOperation base class * Revert wrong removal of toInt casts in examples
* Remove ImageOperationBase * Remove ImageSaver and Operation.save extension function * Introduce Operation.onResult function which can be used instead of Operation.save for saving intermediate results of preprocessing operations * Add an explitit type declaration for pipeline function Co-authored-by: Julia Beliaeva <Julia.Beliaeva@jetbrains.com>
import java.io.File | ||
import java.io.IOException | ||
import java.nio.FloatBuffer | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import kotlin.math.truncate | ||
import kotlin.random.Random | ||
import kotlin.streams.toList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't remove this import, it does not compile without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, for some reason, tests were green in IntelliJ. I added import back and ran tests using the Gradle command line. Now seems fine
* Fix broken import in OnHeapDataset
No description provided.