From 2bd466b63dd3abdf32b6b6eb52c87deaeedbdf15 Mon Sep 17 00:00:00 2001 From: Keon Sanavandi Date: Tue, 6 Feb 2024 18:15:27 -0500 Subject: [PATCH 1/4] Added backend application of transforms --- training/training/routes/image/image.py | 92 +++++++++++++++++++++++ training/training/routes/image/schemas.py | 1 + 2 files changed, 93 insertions(+) diff --git a/training/training/routes/image/image.py b/training/training/routes/image/image.py index 92ccc369..1986a4d7 100644 --- a/training/training/routes/image/image.py +++ b/training/training/routes/image/image.py @@ -9,12 +9,18 @@ from training.core.trainer import ClassificationTrainer from training.routes.image.schemas import ImageParams from training.core.authenticator import FirebaseAuth +import torchvision.transforms as transforms +import json router = Router() @router.post("", auth=FirebaseAuth()) def imageTrain(request: HttpRequest, imageParams: ImageParams): + transforms = json.loads(imageParams.transforms) + train_transorms = transformParser(transforms["train_transforms"]) if transforms["train_transforms"] else transforms.ToTensor() + test_transforms = transformParser(transforms["test_transforms"]) if transforms["test_transforms"] else transforms.ToTensor() + if imageParams.default: dataCreator = ImageDefaultDatasetCreator.fromDefault(imageParams.default) train_loader = dataCreator.createTrainDataset() @@ -38,3 +44,89 @@ def imageTrain(request: HttpRequest, imageParams: ImageParams): print(trainer.generate_confusion_matrix()) print(trainer.generate_AUC_ROC_CURVE()) return trainer.generate_AUC_ROC_CURVE() + +def transformParser(transformArray): + transformsToReturn = transforms.ToTensor() + for x in transformArray: + if (x["type"] == "CenterCrop"): + transformsToReturn = transforms.Compose( + transformsToReturn, + transforms.CenterCrop(x["parameters"]["size"]) + ) + elif (x["type"] == "ColorJitter"): + transformsToReturn = transforms.Compose( + transformsToReturn, + transforms.ColorJitter(x["parameters"]["brightness"], x["parameters"]["contrast"], x["parameters"]["saturation"], x["parameters"]["hue"]) + ) + elif (x["type"] == "FiveCrop"): + transformsToReturn = transforms.Compose( + transformsToReturn, + transforms.FiveCrop(x["parameters"]["size"]) + ) + elif (x["type"] == "Grayscale"): + transformsToReturn = transforms.Compose( + transformsToReturn, + transforms.Grayscale(x["parameters"]["num_output_channels"]) + ) + elif (x["type"] == "Pad"): + transformsToReturn = transforms.Compose( + transformsToReturn, + transforms.Pad(x["parameters"]["padding"]) + ) + elif (x["type"] == "RandomAffine"): + transformsToReturn = transforms.Compose( + transformsToReturn, + transforms.RandomAffine(x["parameters"]["degrees"], x["parameters"]["translate"], x["parameters"]["scale"], x["parameters"]["shear"]) + ) + elif (x["type"] == "RandomCrop"): + transformsToReturn = transforms.Compose( + transformsToReturn, + transforms.RandomCrop(x["parameters"]["size"], x["parameters"]["padding"]) + ) + elif (x["type"] == "RandomGrayscale"): + transformsToReturn = transforms.Compose( + transformsToReturn, + transforms.RandomGrayscale(x["parameters"]["p"]) + ) + elif (x["type"] == "RandomHorizontalFlip"): + transformsToReturn = transforms.Compose( + transformsToReturn, + transforms.RandomHorizontalFlip(x["parameters"]["p"]) + ) + elif (x["type"] == "Resize"): + transformsToReturn = transforms.Compose( + transformsToReturn, + transforms.Resize(x["parameters"]["size"]) + ) + elif (x["type"] == "RandomPerspective"): + transformsToReturn = transforms.Compose( + transformsToReturn, + transforms.RandomPerspective(x["parameters"]["distortion_scale"], x["parameters"]["p"]) + ) + elif (x["type"] == "RandomResizedCrop"): + transformsToReturn = transforms.Compose( + transformsToReturn, + #What do we want to do for other non-single value params + transforms.RandomResizedCrop(x["parameters"]["size"]) + ) + elif (x["type"] == "RandomVerticalFlip"): + transformsToReturn = transforms.Compose( + transformsToReturn, + transforms.RandomVerticalFlip(x["parameters"]["p"]) + ) + elif (x["type"] == "RandomRotation"): + transformsToReturn = transforms.Compose( + transformsToReturn, + transforms.RandomRotation(x["parameters"]["degrees"]) + ) + elif (x["type"] == "TenCrop"): + transformsToReturn = transforms.Compose( + transformsToReturn, + transforms.TenCrop(x["parameters"]["size"]) + ) + elif (x["type"] == "GaussianBlur"): + transformsToReturn = transforms.Compose( + transformsToReturn, + transforms.GaussianBlur(x["parameters"]["kernel_size"]) + ) + return transformsToReturn \ No newline at end of file diff --git a/training/training/routes/image/schemas.py b/training/training/routes/image/schemas.py index 441f1fa0..255f8df0 100644 --- a/training/training/routes/image/schemas.py +++ b/training/training/routes/image/schemas.py @@ -18,3 +18,4 @@ class ImageParams(Schema): test_size: float batch_size: int user_arch: list[LayerParams] + transforms: str From f28638c80f4d73918ce718b11f78ca1e1949b33f Mon Sep 17 00:00:00 2001 From: Keon-San Date: Thu, 7 Mar 2024 16:07:11 -0500 Subject: [PATCH 2/4] Fixed a couple bugs and got it working --- training/training/routes/image/image.py | 74 ++++++++++++----------- training/training/routes/image/schemas.py | 2 +- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/training/training/routes/image/image.py b/training/training/routes/image/image.py index 1986a4d7..1e0233cf 100644 --- a/training/training/routes/image/image.py +++ b/training/training/routes/image/image.py @@ -17,9 +17,11 @@ @router.post("", auth=FirebaseAuth()) def imageTrain(request: HttpRequest, imageParams: ImageParams): - transforms = json.loads(imageParams.transforms) - train_transorms = transformParser(transforms["train_transforms"]) if transforms["train_transforms"] else transforms.ToTensor() - test_transforms = transformParser(transforms["test_transforms"]) if transforms["test_transforms"] else transforms.ToTensor() + transform = {} + if (imageParams.transforms != ""): + transform = json.loads(imageParams.transforms) + train_transorms = transformParser(transform["train_transforms"]) if "train_transforms" in transform else transforms.ToTensor() + test_transforms = transformParser(transform["test_transforms"]) if "test_transforms" in transform else transforms.ToTensor() if imageParams.default: dataCreator = ImageDefaultDatasetCreator.fromDefault(imageParams.default) @@ -27,7 +29,7 @@ def imageTrain(request: HttpRequest, imageParams: ImageParams): test_loader = dataCreator.createTestDataset() model = DLModel.fromLayerParamsList(imageParams.user_arch) optimizer = getOptimizer(model, imageParams.optimizer_name, 0.05) - criterionHandler = getCriterionHandler(imageParams.criterion) + criterionHandler = getCriterionHandler(imageParams.criterion) if imageParams.problem_type == "CLASSIFICATION": trainer = ClassificationTrainer( train_loader, @@ -49,84 +51,84 @@ def transformParser(transformArray): transformsToReturn = transforms.ToTensor() for x in transformArray: if (x["type"] == "CenterCrop"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, - transforms.CenterCrop(x["parameters"]["size"]) + transforms.CenterCrop(x["parameters"]["size"])] ) elif (x["type"] == "ColorJitter"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, - transforms.ColorJitter(x["parameters"]["brightness"], x["parameters"]["contrast"], x["parameters"]["saturation"], x["parameters"]["hue"]) + transforms.ColorJitter(x["parameters"]["brightness"], x["parameters"]["contrast"], x["parameters"]["saturation"], x["parameters"]["hue"])] ) elif (x["type"] == "FiveCrop"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, - transforms.FiveCrop(x["parameters"]["size"]) + transforms.FiveCrop(x["parameters"]["size"])] ) elif (x["type"] == "Grayscale"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, - transforms.Grayscale(x["parameters"]["num_output_channels"]) + transforms.Grayscale(x["parameters"]["num_output_channels"])] ) elif (x["type"] == "Pad"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, - transforms.Pad(x["parameters"]["padding"]) + transforms.Pad(x["parameters"]["padding"])] ) elif (x["type"] == "RandomAffine"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, - transforms.RandomAffine(x["parameters"]["degrees"], x["parameters"]["translate"], x["parameters"]["scale"], x["parameters"]["shear"]) + transforms.RandomAffine(x["parameters"]["degrees"], x["parameters"]["translate"], x["parameters"]["scale"], x["parameters"]["shear"])] ) elif (x["type"] == "RandomCrop"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, - transforms.RandomCrop(x["parameters"]["size"], x["parameters"]["padding"]) + transforms.RandomCrop(x["parameters"]["size"], x["parameters"]["padding"])] ) elif (x["type"] == "RandomGrayscale"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, - transforms.RandomGrayscale(x["parameters"]["p"]) + transforms.RandomGrayscale(x["parameters"]["p"])] ) elif (x["type"] == "RandomHorizontalFlip"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, - transforms.RandomHorizontalFlip(x["parameters"]["p"]) + transforms.RandomHorizontalFlip(x["parameters"]["p"])] ) elif (x["type"] == "Resize"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, - transforms.Resize(x["parameters"]["size"]) + transforms.Resize(x["parameters"]["size"])] ) elif (x["type"] == "RandomPerspective"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, - transforms.RandomPerspective(x["parameters"]["distortion_scale"], x["parameters"]["p"]) + transforms.RandomPerspective(x["parameters"]["distortion_scale"], x["parameters"]["p"])] ) elif (x["type"] == "RandomResizedCrop"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, #What do we want to do for other non-single value params - transforms.RandomResizedCrop(x["parameters"]["size"]) + transforms.RandomResizedCrop(x["parameters"]["size"])] ) elif (x["type"] == "RandomVerticalFlip"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, - transforms.RandomVerticalFlip(x["parameters"]["p"]) + transforms.RandomVerticalFlip(x["parameters"]["p"])] ) elif (x["type"] == "RandomRotation"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, - transforms.RandomRotation(x["parameters"]["degrees"]) + transforms.RandomRotation(x["parameters"]["degrees"])] ) elif (x["type"] == "TenCrop"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, - transforms.TenCrop(x["parameters"]["size"]) + transforms.TenCrop(x["parameters"]["size"])] ) elif (x["type"] == "GaussianBlur"): - transformsToReturn = transforms.Compose( + transformsToReturn = transforms.Compose([ transformsToReturn, - transforms.GaussianBlur(x["parameters"]["kernel_size"]) + transforms.GaussianBlur(x["parameters"]["kernel_size"])] ) return transformsToReturn \ No newline at end of file diff --git a/training/training/routes/image/schemas.py b/training/training/routes/image/schemas.py index 255f8df0..b1e8751d 100644 --- a/training/training/routes/image/schemas.py +++ b/training/training/routes/image/schemas.py @@ -18,4 +18,4 @@ class ImageParams(Schema): test_size: float batch_size: int user_arch: list[LayerParams] - transforms: str + transforms: str = "" From d154ac8e4b818aa266d23868c38b8d2dabffc550 Mon Sep 17 00:00:00 2001 From: Keon-San Date: Fri, 8 Mar 2024 00:08:02 +0000 Subject: [PATCH 3/4] :art: Auto-generated directory tree for repository in Architecture.md --- .github/Architecture.md | 302 ++++++++++++++++++++-------------------- 1 file changed, 151 insertions(+), 151 deletions(-) diff --git a/.github/Architecture.md b/.github/Architecture.md index c381f867..e1be534c 100644 --- a/.github/Architecture.md +++ b/.github/Architecture.md @@ -5,24 +5,16 @@ ``` 📦 training | |- 📂 training: -| | |- 📂 core: -| | | |- 📜 dataset.py : read in the dataset through URL or file upload -| | | |- 📜 criterion.py -| | | |- 📜 optimizer.py : what optimizer to use (ie: SGD or Adam for now) -| | | |- 📜 __init__.py -| | | |- 📜 dl_model.py : torch model based on user specifications from drag and drop -| | | |- 📜 trainer.py -| | | |- 📜 authenticator.py | | |- 📂 routes: +| | | |- 📂 image: +| | | | |- 📜 schemas.py +| | | | |- 📜 __init__.py +| | | | |- 📜 image.py | | | |- 📂 datasets: | | | | |- 📂 default: | | | | | |- 📜 schemas.py -| | | | | |- 📜 __init__.py | | | | | |- 📜 columns.py -| | | | |- 📜 __init__.py -| | | |- 📂 image: -| | | | |- 📜 image.py -| | | | |- 📜 schemas.py +| | | | | |- 📜 __init__.py | | | | |- 📜 __init__.py | | | |- 📂 tabular: | | | | |- 📜 tabular.py @@ -33,198 +25,206 @@ | | |- 📂 middleware: | | | |- 📜 health_check_middleware.py | | | |- 📜 __init__.py +| | |- 📂 core: +| | | |- 📜 optimizer.py : what optimizer to use (ie: SGD or Adam for now) +| | | |- 📜 criterion.py +| | | |- 📜 dl_model.py : torch model based on user specifications from drag and drop +| | | |- 📜 dataset.py : read in the dataset through URL or file upload +| | | |- 📜 authenticator.py +| | | |- 📜 __init__.py +| | | |- 📜 trainer.py +| | |- 📜 wsgi.py +| | |- 📜 settings.py | | |- 📜 urls.py | | |- 📜 asgi.py | | |- 📜 __init__.py -| | |- 📜 wsgi.py -| | |- 📜 settings.py -| |- 📜 README.md -| |- 📜 docker-compose.prod.yml | |- 📜 pytest.ini -| |- 📜 poetry.lock | |- 📜 cli.py +| |- 📜 README.md +| |- 📜 Dockerfile.prod | |- 📜 pyproject.toml -| |- 📜 environment.yml +| |- 📜 docker-compose.yml +| |- 📜 poetry.lock | |- 📜 Dockerfile -| |- 📜 Dockerfile.prod | |- 📜 manage.py -| |- 📜 docker-compose.yml +| |- 📜 docker-compose.prod.yml +| |- 📜 environment.yml ``` ## Frontend Architecture ``` 📦 frontend +| |- 📂 public: +| | |- 📂 images: +| | | |- 📂 learn_mod_images: +| | | | |- 📜 LeakyReLUactivation.png +| | | | |- 📜 neuralnet.png +| | | | |- 📜 tanhactivation.png +| | | | |- 📜 lossExample.png +| | | | |- 📜 sigmoidfunction.png +| | | | |- 📜 neuron.png +| | | | |- 📜 ReLUactivation.png +| | | | |- 📜 sigmoidactivation.png +| | | | |- 📜 lossExampleEquation.png +| | | | |- 📜 neuronWithEquation.png +| | | | |- 📜 robotImage.jpg +| | | | |- 📜 binarystepactivation.png +| | | | |- 📜 lossExampleTable.png +| | | |- 📂 wiki_images: +| | | | |- 📜 avgpool_maxpool.gif +| | | | |- 📜 tanh_equation.png +| | | | |- 📜 maxpool2d.gif +| | | | |- 📜 dropout_diagram.png +| | | | |- 📜 batchnorm_diagram.png +| | | | |- 📜 softmax_equation.png : PNG file of Softmax equation +| | | | |- 📜 tanh_plot.png +| | | | |- 📜 sigmoid_equation.png +| | | | |- 📜 conv2d.gif +| | | | |- 📜 conv2d2.gif +| | | |- 📂 logos: +| | | | |- 📂 dlp_branding: +| | | | | |- 📜 dlp-logo.svg : DLP Logo, duplicate of files in public, but essential as the frontend can't read public +| | | | | |- 📜 dlp-logo.png : DLP Logo, duplicate of files in public, but essential as the frontend can't read public +| | | | |- 📜 pytorch-logo.png +| | | | |- 📜 dsgt-logo-dark.png +| | | | |- 📜 flask-logo.png +| | | | |- 📜 dsgt-logo-light.png +| | | | |- 📜 aws-logo.png +| | | | |- 📜 github.png +| | | | |- 📜 google.png +| | | | |- 📜 pandas-logo.png +| | | | |- 📜 python-logo.png +| | | | |- 📜 dsgt-logo-white-back.png +| | | | |- 📜 react-logo.png +| | | |- 📜 demo_video.gif : GIF tutorial of a simple classification training session +| | |- 📜 dlp-logo.ico : DLP Logo +| | |- 📜 manifest.json : Default React file for choosing icon based on +| | |- 📜 index.html : Base HTML file that will be initially rendered +| | |- 📜 robots.txt +| |- 📂 layer_docs: +| | |- 📜 Linear.md : Doc for Linear layer +| | |- 📜 Softmax.md : Doc for Softmax layer +| | |- 📜 ReLU.md : Doc for ReLU later +| | |- 📜 softmax_equation.png : PNG file of Softmax equation | |- 📂 src: -| | |- 📂 pages: -| | | |- 📂 train: -| | | | |- 📜 [train_space_id].tsx -| | | | |- 📜 index.tsx -| | | |- 📜 settings.tsx -| | | |- 📜 feedback.tsx -| | | |- 📜 forgot.tsx -| | | |- 📜 learn.tsx -| | | |- 📜 dashboard.tsx -| | | |- 📜 login.tsx -| | | |- 📜 _document.tsx -| | | |- 📜 _app.tsx -| | | |- 📜 about.tsx -| | | |- 📜 wiki.tsx -| | | |- 📜 LearnContent.tsx | | |- 📂 features: -| | | |- 📂 Feedback: -| | | | |- 📂 redux: -| | | | | |- 📜 feedbackApi.ts | | | |- 📂 Dashboard: +| | | | |- 📂 redux: +| | | | | |- 📜 dashboardApi.ts | | | | |- 📂 components: | | | | | |- 📜 TrainDataGrid.tsx | | | | | |- 📜 TrainBarChart.tsx | | | | | |- 📜 TrainDoughnutChart.tsx +| | | |- 📂 LearnMod: +| | | | |- 📜 FRQuestion.tsx +| | | | |- 📜 MCQuestion.tsx +| | | | |- 📜 ClassCard.tsx +| | | | |- 📜 ImageComponent.tsx +| | | | |- 📜 LearningModulesContent.tsx +| | | | |- 📜 ModulesSideBar.tsx +| | | | |- 📜 Exercise.tsx +| | | |- 📂 Feedback: | | | | |- 📂 redux: -| | | | | |- 📜 dashboardApi.ts +| | | | | |- 📜 feedbackApi.ts | | | |- 📂 Train: -| | | | |- 📂 constants: -| | | | | |- 📜 trainConstants.ts -| | | | |- 📂 components: -| | | | | |- 📜 DatasetStepLayout.tsx -| | | | | |- 📜 CreateTrainspace.tsx -| | | | | |- 📜 TrainspaceLayout.tsx | | | | |- 📂 redux: | | | | | |- 📜 trainspaceApi.ts | | | | | |- 📜 trainspaceSlice.ts | | | | |- 📂 features: -| | | | | |- 📂 Image: -| | | | | | |- 📂 constants: -| | | | | | | |- 📜 imageConstants.ts -| | | | | | |- 📂 components: -| | | | | | | |- 📜 ImageTrainspace.tsx -| | | | | | | |- 📜 ImageFlow.tsx -| | | | | | | |- 📜 ImageReviewStep.tsx -| | | | | | | |- 📜 ImageParametersStep.tsx -| | | | | | | |- 📜 ImageDatasetStep.tsx -| | | | | | |- 📂 redux: -| | | | | | | |- 📜 imageApi.ts -| | | | | | | |- 📜 imageActions.ts -| | | | | | |- 📂 types: -| | | | | | | |- 📜 imageTypes.ts -| | | | | | |- 📜 index.ts | | | | | |- 📂 Tabular: +| | | | | | |- 📂 redux: +| | | | | | | |- 📜 tabularActions.ts +| | | | | | | |- 📜 tabularApi.ts | | | | | | |- 📂 constants: | | | | | | | |- 📜 tabularConstants.ts +| | | | | | |- 📂 types: +| | | | | | | |- 📜 tabularTypes.ts | | | | | | |- 📂 components: -| | | | | | | |- 📜 TabularTrainspace.tsx +| | | | | | | |- 📜 TabularFlow.tsx | | | | | | | |- 📜 TabularParametersStep.tsx +| | | | | | | |- 📜 TabularTrainspace.tsx | | | | | | | |- 📜 TabularDatasetStep.tsx -| | | | | | | |- 📜 TabularFlow.tsx | | | | | | | |- 📜 TabularReviewStep.tsx +| | | | | | |- 📜 index.ts +| | | | | |- 📂 Image: | | | | | | |- 📂 redux: -| | | | | | | |- 📜 tabularActions.ts -| | | | | | | |- 📜 tabularApi.ts +| | | | | | | |- 📜 imageApi.ts +| | | | | | | |- 📜 imageActions.ts +| | | | | | |- 📂 constants: +| | | | | | | |- 📜 imageConstants.ts | | | | | | |- 📂 types: -| | | | | | | |- 📜 tabularTypes.ts +| | | | | | | |- 📜 imageTypes.ts +| | | | | | |- 📂 components: +| | | | | | | |- 📜 ImageReviewStep.tsx +| | | | | | | |- 📜 ImageFlow.tsx +| | | | | | | |- 📜 ImageParametersStep.tsx +| | | | | | | |- 📜 ImageDatasetStep.tsx +| | | | | | | |- 📜 ImageTrainspace.tsx | | | | | | |- 📜 index.ts +| | | | |- 📂 constants: +| | | | | |- 📜 trainConstants.ts | | | | |- 📂 types: | | | | | |- 📜 trainTypes.ts +| | | | |- 📂 components: +| | | | | |- 📜 CreateTrainspace.tsx +| | | | | |- 📜 DatasetStepLayout.tsx +| | | | | |- 📜 TrainspaceLayout.tsx | | | |- 📂 OpenAi: | | | | |- 📜 openAiUtils.ts -| | | |- 📂 LearnMod: -| | | | |- 📜 ModulesSideBar.tsx -| | | | |- 📜 Exercise.tsx -| | | | |- 📜 LearningModulesContent.tsx -| | | | |- 📜 FRQuestion.tsx -| | | | |- 📜 ImageComponent.tsx -| | | | |- 📜 ClassCard.tsx -| | | | |- 📜 MCQuestion.tsx -| | |- 📂 backend_outputs: -| | | |- 📜 model.pkl -| | | |- 📜 my_deep_learning_model.onnx : Last ONNX file output -| | | |- 📜 model.pt : Last model.pt output | | |- 📂 common: -| | | |- 📂 components: -| | | | |- 📜 Spacer.tsx -| | | | |- 📜 Footer.tsx -| | | | |- 📜 DlpTooltip.tsx -| | | | |- 📜 EmailInput.tsx -| | | | |- 📜 HtmlTooltip.tsx -| | | | |- 📜 NavBarMain.tsx -| | | | |- 📜 TitleText.tsx -| | | | |- 📜 ClientOnlyPortal.tsx +| | | |- 📂 styles: +| | | | |- 📜 globals.css +| | | | |- 📜 Home.module.css | | | |- 📂 redux: -| | | | |- 📜 store.ts -| | | | |- 📜 train.ts | | | | |- 📜 userLogin.ts +| | | | |- 📜 store.ts | | | | |- 📜 hooks.ts | | | | |- 📜 backendApi.ts +| | | | |- 📜 train.ts | | | |- 📂 utils: -| | | | |- 📜 dateFormat.ts | | | | |- 📜 firebase.ts | | | | |- 📜 dndHelpers.ts -| | | |- 📂 styles: -| | | | |- 📜 Home.module.css -| | | | |- 📜 globals.css -| | |- 📜 next-env.d.ts -| | |- 📜 GlobalStyle.ts -| | |- 📜 iris.csv : Sample CSV data +| | | | |- 📜 dateFormat.ts +| | | |- 📂 components: +| | | | |- 📜 NavBarMain.tsx +| | | | |- 📜 Footer.tsx +| | | | |- 📜 ClientOnlyPortal.tsx +| | | | |- 📜 Spacer.tsx +| | | | |- 📜 EmailInput.tsx +| | | | |- 📜 TitleText.tsx +| | | | |- 📜 HtmlTooltip.tsx +| | | | |- 📜 DlpTooltip.tsx +| | |- 📂 backend_outputs: +| | | |- 📜 model.pkl +| | | |- 📜 my_deep_learning_model.onnx : Last ONNX file output +| | | |- 📜 model.pt : Last model.pt output +| | |- 📂 pages: +| | | |- 📂 train: +| | | | |- 📜 [train_space_id].tsx +| | | | |- 📜 index.tsx +| | | |- 📜 login.tsx +| | | |- 📜 feedback.tsx +| | | |- 📜 _app.tsx +| | | |- 📜 forgot.tsx +| | | |- 📜 learn.tsx +| | | |- 📜 LearnContent.tsx +| | | |- 📜 settings.tsx +| | | |- 📜 dashboard.tsx +| | | |- 📜 about.tsx +| | | |- 📜 wiki.tsx +| | | |- 📜 _document.tsx | | |- 📜 constants.ts -| |- 📂 layer_docs: -| | |- 📜 softmax_equation.png : PNG file of Softmax equation -| | |- 📜 Linear.md : Doc for Linear layer -| | |- 📜 Softmax.md : Doc for Softmax layer -| | |- 📜 ReLU.md : Doc for ReLU later -| |- 📂 public: -| | |- 📂 images: -| | | |- 📂 wiki_images: -| | | | |- 📜 softmax_equation.png : PNG file of Softmax equation -| | | | |- 📜 tanh_plot.png -| | | | |- 📜 conv2d.gif -| | | | |- 📜 conv2d2.gif -| | | | |- 📜 avgpool_maxpool.gif -| | | | |- 📜 sigmoid_equation.png -| | | | |- 📜 batchnorm_diagram.png -| | | | |- 📜 maxpool2d.gif -| | | | |- 📜 tanh_equation.png -| | | | |- 📜 dropout_diagram.png -| | | |- 📂 learn_mod_images: -| | | | |- 📜 neuronWithEquation.png -| | | | |- 📜 robotImage.jpg -| | | | |- 📜 neuralnet.png -| | | | |- 📜 sigmoidactivation.png -| | | | |- 📜 lossExample.png -| | | | |- 📜 binarystepactivation.png -| | | | |- 📜 tanhactivation.png -| | | | |- 📜 LeakyReLUactivation.png -| | | | |- 📜 sigmoidfunction.png -| | | | |- 📜 lossExampleTable.png -| | | | |- 📜 lossExampleEquation.png -| | | | |- 📜 neuron.png -| | | | |- 📜 ReLUactivation.png -| | | |- 📂 logos: -| | | | |- 📂 dlp_branding: -| | | | | |- 📜 dlp-logo.svg : DLP Logo, duplicate of files in public, but essential as the frontend can't read public -| | | | | |- 📜 dlp-logo.png : DLP Logo, duplicate of files in public, but essential as the frontend can't read public -| | | | |- 📜 dsgt-logo-white-back.png -| | | | |- 📜 pytorch-logo.png -| | | | |- 📜 google.png -| | | | |- 📜 flask-logo.png -| | | | |- 📜 dsgt-logo-dark.png -| | | | |- 📜 pandas-logo.png -| | | | |- 📜 dsgt-logo-light.png -| | | | |- 📜 github.png -| | | | |- 📜 react-logo.png -| | | | |- 📜 python-logo.png -| | | | |- 📜 aws-logo.png -| | | |- 📜 demo_video.gif : GIF tutorial of a simple classification training session -| | |- 📜 manifest.json : Default React file for choosing icon based on -| | |- 📜 dlp-logo.ico : DLP Logo -| | |- 📜 index.html : Base HTML file that will be initially rendered -| | |- 📜 robots.txt -| |- 📜 .eslintrc.json +| | |- 📜 iris.csv : Sample CSV data +| | |- 📜 GlobalStyle.ts +| | |- 📜 next-env.d.ts | |- 📜 .eslintignore +| |- 📜 tsconfig.json +| |- 📜 .eslintrc.json | |- 📜 pnpm-lock.yaml +| |- 📜 jest.config.js | |- 📜 package.json | |- 📜 next.config.js -| |- 📜 jest.config.js | |- 📜 next-env.d.ts -| |- 📜 tsconfig.json ``` From d0f27cfb5b259f54feabf9d371c3466a4e5cf058 Mon Sep 17 00:00:00 2001 From: Keon-San Date: Fri, 8 Mar 2024 00:08:16 +0000 Subject: [PATCH 4/4] :art: Format Python code with psf/black --- training/training/routes/image/image.py | 211 ++++++++++++++---------- 1 file changed, 124 insertions(+), 87 deletions(-) diff --git a/training/training/routes/image/image.py b/training/training/routes/image/image.py index 1e0233cf..178703a8 100644 --- a/training/training/routes/image/image.py +++ b/training/training/routes/image/image.py @@ -18,18 +18,26 @@ @router.post("", auth=FirebaseAuth()) def imageTrain(request: HttpRequest, imageParams: ImageParams): transform = {} - if (imageParams.transforms != ""): + if imageParams.transforms != "": transform = json.loads(imageParams.transforms) - train_transorms = transformParser(transform["train_transforms"]) if "train_transforms" in transform else transforms.ToTensor() - test_transforms = transformParser(transform["test_transforms"]) if "test_transforms" in transform else transforms.ToTensor() - + train_transorms = ( + transformParser(transform["train_transforms"]) + if "train_transforms" in transform + else transforms.ToTensor() + ) + test_transforms = ( + transformParser(transform["test_transforms"]) + if "test_transforms" in transform + else transforms.ToTensor() + ) + if imageParams.default: dataCreator = ImageDefaultDatasetCreator.fromDefault(imageParams.default) train_loader = dataCreator.createTrainDataset() test_loader = dataCreator.createTestDataset() model = DLModel.fromLayerParamsList(imageParams.user_arch) optimizer = getOptimizer(model, imageParams.optimizer_name, 0.05) - criterionHandler = getCriterionHandler(imageParams.criterion) + criterionHandler = getCriterionHandler(imageParams.criterion) if imageParams.problem_type == "CLASSIFICATION": trainer = ClassificationTrainer( train_loader, @@ -47,88 +55,117 @@ def imageTrain(request: HttpRequest, imageParams: ImageParams): print(trainer.generate_AUC_ROC_CURVE()) return trainer.generate_AUC_ROC_CURVE() + def transformParser(transformArray): transformsToReturn = transforms.ToTensor() for x in transformArray: - if (x["type"] == "CenterCrop"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - transforms.CenterCrop(x["parameters"]["size"])] - ) - elif (x["type"] == "ColorJitter"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - transforms.ColorJitter(x["parameters"]["brightness"], x["parameters"]["contrast"], x["parameters"]["saturation"], x["parameters"]["hue"])] - ) - elif (x["type"] == "FiveCrop"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - transforms.FiveCrop(x["parameters"]["size"])] - ) - elif (x["type"] == "Grayscale"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - transforms.Grayscale(x["parameters"]["num_output_channels"])] - ) - elif (x["type"] == "Pad"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - transforms.Pad(x["parameters"]["padding"])] - ) - elif (x["type"] == "RandomAffine"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - transforms.RandomAffine(x["parameters"]["degrees"], x["parameters"]["translate"], x["parameters"]["scale"], x["parameters"]["shear"])] - ) - elif (x["type"] == "RandomCrop"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - transforms.RandomCrop(x["parameters"]["size"], x["parameters"]["padding"])] - ) - elif (x["type"] == "RandomGrayscale"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - transforms.RandomGrayscale(x["parameters"]["p"])] - ) - elif (x["type"] == "RandomHorizontalFlip"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - transforms.RandomHorizontalFlip(x["parameters"]["p"])] - ) - elif (x["type"] == "Resize"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - transforms.Resize(x["parameters"]["size"])] - ) - elif (x["type"] == "RandomPerspective"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - transforms.RandomPerspective(x["parameters"]["distortion_scale"], x["parameters"]["p"])] - ) - elif (x["type"] == "RandomResizedCrop"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - #What do we want to do for other non-single value params - transforms.RandomResizedCrop(x["parameters"]["size"])] - ) - elif (x["type"] == "RandomVerticalFlip"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - transforms.RandomVerticalFlip(x["parameters"]["p"])] - ) - elif (x["type"] == "RandomRotation"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - transforms.RandomRotation(x["parameters"]["degrees"])] - ) - elif (x["type"] == "TenCrop"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - transforms.TenCrop(x["parameters"]["size"])] - ) - elif (x["type"] == "GaussianBlur"): - transformsToReturn = transforms.Compose([ - transformsToReturn, - transforms.GaussianBlur(x["parameters"]["kernel_size"])] - ) - return transformsToReturn \ No newline at end of file + if x["type"] == "CenterCrop": + transformsToReturn = transforms.Compose( + [transformsToReturn, transforms.CenterCrop(x["parameters"]["size"])] + ) + elif x["type"] == "ColorJitter": + transformsToReturn = transforms.Compose( + [ + transformsToReturn, + transforms.ColorJitter( + x["parameters"]["brightness"], + x["parameters"]["contrast"], + x["parameters"]["saturation"], + x["parameters"]["hue"], + ), + ] + ) + elif x["type"] == "FiveCrop": + transformsToReturn = transforms.Compose( + [transformsToReturn, transforms.FiveCrop(x["parameters"]["size"])] + ) + elif x["type"] == "Grayscale": + transformsToReturn = transforms.Compose( + [ + transformsToReturn, + transforms.Grayscale(x["parameters"]["num_output_channels"]), + ] + ) + elif x["type"] == "Pad": + transformsToReturn = transforms.Compose( + [transformsToReturn, transforms.Pad(x["parameters"]["padding"])] + ) + elif x["type"] == "RandomAffine": + transformsToReturn = transforms.Compose( + [ + transformsToReturn, + transforms.RandomAffine( + x["parameters"]["degrees"], + x["parameters"]["translate"], + x["parameters"]["scale"], + x["parameters"]["shear"], + ), + ] + ) + elif x["type"] == "RandomCrop": + transformsToReturn = transforms.Compose( + [ + transformsToReturn, + transforms.RandomCrop( + x["parameters"]["size"], x["parameters"]["padding"] + ), + ] + ) + elif x["type"] == "RandomGrayscale": + transformsToReturn = transforms.Compose( + [transformsToReturn, transforms.RandomGrayscale(x["parameters"]["p"])] + ) + elif x["type"] == "RandomHorizontalFlip": + transformsToReturn = transforms.Compose( + [ + transformsToReturn, + transforms.RandomHorizontalFlip(x["parameters"]["p"]), + ] + ) + elif x["type"] == "Resize": + transformsToReturn = transforms.Compose( + [transformsToReturn, transforms.Resize(x["parameters"]["size"])] + ) + elif x["type"] == "RandomPerspective": + transformsToReturn = transforms.Compose( + [ + transformsToReturn, + transforms.RandomPerspective( + x["parameters"]["distortion_scale"], x["parameters"]["p"] + ), + ] + ) + elif x["type"] == "RandomResizedCrop": + transformsToReturn = transforms.Compose( + [ + transformsToReturn, + # What do we want to do for other non-single value params + transforms.RandomResizedCrop(x["parameters"]["size"]), + ] + ) + elif x["type"] == "RandomVerticalFlip": + transformsToReturn = transforms.Compose( + [ + transformsToReturn, + transforms.RandomVerticalFlip(x["parameters"]["p"]), + ] + ) + elif x["type"] == "RandomRotation": + transformsToReturn = transforms.Compose( + [ + transformsToReturn, + transforms.RandomRotation(x["parameters"]["degrees"]), + ] + ) + elif x["type"] == "TenCrop": + transformsToReturn = transforms.Compose( + [transformsToReturn, transforms.TenCrop(x["parameters"]["size"])] + ) + elif x["type"] == "GaussianBlur": + transformsToReturn = transforms.Compose( + [ + transformsToReturn, + transforms.GaussianBlur(x["parameters"]["kernel_size"]), + ] + ) + return transformsToReturn