diff --git a/config/__init__.py b/config/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..6f7cab1d3b44057a956a458d4e5274aba20bc7cd --- /dev/null +++ b/config/__init__.py @@ -0,0 +1,6 @@ +import toml +import os + +config_file:str = os.path.join(os.path.dirname(__file__),'config.toml') + +CONFIG = toml.load(config_file) \ No newline at end of file diff --git a/config/config.toml b/config/config.toml new file mode 100644 index 0000000000000000000000000000000000000000..264a5e9e4ff47dfe3bb244530d1242ab1a194144 --- /dev/null +++ b/config/config.toml @@ -0,0 +1,24 @@ +batch_size = 128 +shuffle = true +num_workers= 0 +pin_memory = false + +[optimizer] +lr = 0.1 +momentum = 0.9 + +[scheduler] +step_size = 15 +gamma = 0.1 + + +[training] +num_epochs = 15 + + +[data] +dir_path = 'C:\Users\muthu\GitHub\DATA 📁\' + +[model] +dropout_rate = 0.01 +bias = false \ No newline at end of file diff --git a/data/__init__.py b/data/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..da55fc319654dba0bf0a4a6dbe057856add0367d --- /dev/null +++ b/data/__init__.py @@ -0,0 +1 @@ +from .data import LitMNISTDataModule \ No newline at end of file diff --git a/data/data.py b/data/data.py new file mode 100644 index 0000000000000000000000000000000000000000..4a654468bad9fe86f03b2d1d3d9b10d3b81b8843 --- /dev/null +++ b/data/data.py @@ -0,0 +1,51 @@ +from typing import Callable,List,Any +from pathlib import Path + +from lightning import LightningDataModule +from lightning.pytorch.utilities.types import TRAIN_DATALOADERS,EVAL_DATALOADERS +import torch +from torch.utils.data import DataLoader,random_split +from torchvision import transforms +from torchvision.datasets import MNIST + +device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu') + +class LitMNISTDataModule(LightningDataModule): + def __init__( + self, + data_dir:Path = Path('.'), + batch_size:int = 32, + num_workers:int = 0, + test_transform:Callable = transforms.Compose([transforms.ToTensor(),transforms.Normalize(mean=(.1307,),std=(.3081,))]), + train_transform:Callable = transforms.Compose([transforms.ToTensor(),transforms.Normalize(mean=(.1307,),std=(.3081,))]) + ) -> None: + super().__init__() + self.data_dir:Path = data_dir + self.batch_size:int = batch_size + self.num_workers:int = num_workers + self.test_transform:Callable = test_transform + self.train_transform:Callable = train_transform + self.save_hyperparameters() + + def prepare_data(self) -> None: + MNIST(self.data_dir,train=True,download=True) + MNIST(self.data_dir,train=False,download=True) + + def setup(self, stage: str=None) -> None: + if stage=="fit" or stage is None: + _mnist_full = MNIST(self.data_dir,train=True,transform=self.train_transform) + self.mnist_train, self.mnist_val = random_split(_mnist_full,[.9,.1],generator=torch.Generator(device)) + + if stage=='test' or stage is None: + self.mnist_test = MNIST(self.data_dir,train=False, transform=self.test_transform) + + + def train_dataloader(self) -> TRAIN_DATALOADERS: + return DataLoader(self.mnist_train,batch_size=self.batch_size,num_workers=self.num_workers,collate_fn=None,shuffle=True,generator= torch.Generator(device) ) + + def val_dataloader(self) -> EVAL_DATALOADERS: + return DataLoader(self.mnist_val,batch_size=self.batch_size,num_workers=self.num_workers,collate_fn=None,shuffle=False,generator= torch.Generator(device)) + + def test_dataloader(self) -> EVAL_DATALOADERS: + return DataLoader(self.mnist_test,batch_size=self.batch_size,num_workers=self.num_workers,collate_fn=None,shuffle=False,generator= torch.Generator(device)) + \ No newline at end of file diff --git a/hand_made_numbers/number_eight.png b/hand_made_numbers/number_eight.png new file mode 100644 index 0000000000000000000000000000000000000000..03956f5b29325903ed221c6dfe90d686c62b4dbd Binary files /dev/null and b/hand_made_numbers/number_eight.png differ diff --git a/hand_made_numbers/number_five.png b/hand_made_numbers/number_five.png new file mode 100644 index 0000000000000000000000000000000000000000..edb0d2591deec134ff79190a0adebd0ac32014b6 Binary files /dev/null and b/hand_made_numbers/number_five.png differ diff --git a/hand_made_numbers/number_four.png b/hand_made_numbers/number_four.png new file mode 100644 index 0000000000000000000000000000000000000000..a05704dbf9ba53ca4514b53b82559ad056540ef6 Binary files /dev/null and b/hand_made_numbers/number_four.png differ diff --git a/hand_made_numbers/number_nine.png b/hand_made_numbers/number_nine.png new file mode 100644 index 0000000000000000000000000000000000000000..10e5143c7788b41105ad1e14da4f2a6683293896 Binary files /dev/null and b/hand_made_numbers/number_nine.png differ diff --git a/hand_made_numbers/number_one.png b/hand_made_numbers/number_one.png new file mode 100644 index 0000000000000000000000000000000000000000..f11101e3d42eeb8714a4079a268772adbc582026 Binary files /dev/null and b/hand_made_numbers/number_one.png differ diff --git a/hand_made_numbers/number_seven.png b/hand_made_numbers/number_seven.png new file mode 100644 index 0000000000000000000000000000000000000000..2565141067e921bcb9e5631e9a2b6a963aa659cd Binary files /dev/null and b/hand_made_numbers/number_seven.png differ diff --git a/hand_made_numbers/number_six.png b/hand_made_numbers/number_six.png new file mode 100644 index 0000000000000000000000000000000000000000..efd22673bbe7182f4439520019700ee85df1349c Binary files /dev/null and b/hand_made_numbers/number_six.png differ diff --git a/hand_made_numbers/number_three.png b/hand_made_numbers/number_three.png new file mode 100644 index 0000000000000000000000000000000000000000..d57267d5fe9a56e13c6c48796d19344d4e0409f7 Binary files /dev/null and b/hand_made_numbers/number_three.png differ diff --git a/hand_made_numbers/number_two.png b/hand_made_numbers/number_two.png new file mode 100644 index 0000000000000000000000000000000000000000..f71460b02656b548b934e779886c3705a3cabe85 Binary files /dev/null and b/hand_made_numbers/number_two.png differ diff --git a/hand_made_numbers/number_zero.png b/hand_made_numbers/number_zero.png new file mode 100644 index 0000000000000000000000000000000000000000..b93d09af4e5e48982bf554cbb2fc425bc99f7f7b Binary files /dev/null and b/hand_made_numbers/number_zero.png differ diff --git a/numbers/img_0.png b/numbers/img_0.png new file mode 100644 index 0000000000000000000000000000000000000000..4da78096e56a0abed1b8383e8b4f58752347879f Binary files /dev/null and b/numbers/img_0.png differ diff --git a/numbers/img_1.png b/numbers/img_1.png new file mode 100644 index 0000000000000000000000000000000000000000..bf0c0df33410f25cf648ee429e093d35ef4bdc08 Binary files /dev/null and b/numbers/img_1.png differ diff --git a/numbers/img_10.png b/numbers/img_10.png new file mode 100644 index 0000000000000000000000000000000000000000..9f9b9ea3cdd8796ffb6b330de233dc40e0d43ae5 Binary files /dev/null and b/numbers/img_10.png differ diff --git a/numbers/img_100.png b/numbers/img_100.png new file mode 100644 index 0000000000000000000000000000000000000000..50c596bff36f585c62231dd075c6cd143afe2f82 Binary files /dev/null and b/numbers/img_100.png differ diff --git a/numbers/img_101.png b/numbers/img_101.png new file mode 100644 index 0000000000000000000000000000000000000000..6e8a9c4872d38b966d63a9d2d1160cb795632540 Binary files /dev/null and b/numbers/img_101.png differ diff --git a/numbers/img_102.png b/numbers/img_102.png new file mode 100644 index 0000000000000000000000000000000000000000..bfe0ac7f1130d2f04424bd9a3789db81342f1646 Binary files /dev/null and b/numbers/img_102.png differ diff --git a/numbers/img_103.png b/numbers/img_103.png new file mode 100644 index 0000000000000000000000000000000000000000..a6c9af75a7b683b99ca8499c41b1c46d28b738d2 Binary files /dev/null and b/numbers/img_103.png differ diff --git a/numbers/img_104.png b/numbers/img_104.png new file mode 100644 index 0000000000000000000000000000000000000000..69f6ebb694a4ec25fb96ae4a98a07263bcab2706 Binary files /dev/null and b/numbers/img_104.png differ diff --git a/numbers/img_105.png b/numbers/img_105.png new file mode 100644 index 0000000000000000000000000000000000000000..fd151e2a5ab53fba7ba32f473548b5b68f4b11ca Binary files /dev/null and b/numbers/img_105.png differ diff --git a/numbers/img_106.png b/numbers/img_106.png new file mode 100644 index 0000000000000000000000000000000000000000..f64114cdf59dd0ae08e5104ae3aff898cf0b65fe Binary files /dev/null and b/numbers/img_106.png differ diff --git a/numbers/img_107.png b/numbers/img_107.png new file mode 100644 index 0000000000000000000000000000000000000000..37cd4c0113b4703f6ee9db991acce916a3c4b9b2 Binary files /dev/null and b/numbers/img_107.png differ diff --git a/numbers/img_108.png b/numbers/img_108.png new file mode 100644 index 0000000000000000000000000000000000000000..56ce08c81ad0bee6030f6a4e073603778c28acf2 Binary files /dev/null and b/numbers/img_108.png differ diff --git a/numbers/img_109.png b/numbers/img_109.png new file mode 100644 index 0000000000000000000000000000000000000000..e5df59992f3a4edce1067489336fe0c8247f1a94 Binary files /dev/null and b/numbers/img_109.png differ diff --git a/numbers/img_11.png b/numbers/img_11.png new file mode 100644 index 0000000000000000000000000000000000000000..496cdf3b818fb481c8e9ba9b0726d13b95e24e19 Binary files /dev/null and b/numbers/img_11.png differ diff --git a/numbers/img_110.png b/numbers/img_110.png new file mode 100644 index 0000000000000000000000000000000000000000..9728ed833a10e44eafdd64e5e8aecd6615f816c8 Binary files /dev/null and b/numbers/img_110.png differ diff --git a/numbers/img_111.png b/numbers/img_111.png new file mode 100644 index 0000000000000000000000000000000000000000..52f64d6256c4cf139a291d32faf3434bff5131b9 Binary files /dev/null and b/numbers/img_111.png differ diff --git a/numbers/img_112.png b/numbers/img_112.png new file mode 100644 index 0000000000000000000000000000000000000000..88ce80691d921d4c24118e6f3cc63c65464b805d Binary files /dev/null and b/numbers/img_112.png differ diff --git a/numbers/img_113.png b/numbers/img_113.png new file mode 100644 index 0000000000000000000000000000000000000000..33e5929f3ce68eee06b449268ef90fee2f732a2c Binary files /dev/null and b/numbers/img_113.png differ diff --git a/numbers/img_114.png b/numbers/img_114.png new file mode 100644 index 0000000000000000000000000000000000000000..c1fd71abfa59d5a1f09457b2c45711ed5b404d22 Binary files /dev/null and b/numbers/img_114.png differ diff --git a/numbers/img_115.png b/numbers/img_115.png new file mode 100644 index 0000000000000000000000000000000000000000..d88c39bf389662bd5c31e446838487db97a1b921 Binary files /dev/null and b/numbers/img_115.png differ diff --git a/numbers/img_116.png b/numbers/img_116.png new file mode 100644 index 0000000000000000000000000000000000000000..7bc7413406f625085906370bb318b262fd9a0b75 Binary files /dev/null and b/numbers/img_116.png differ diff --git a/numbers/img_117.png b/numbers/img_117.png new file mode 100644 index 0000000000000000000000000000000000000000..f2a93bead8b7bf6622803aef390e2a1bc1468160 Binary files /dev/null and b/numbers/img_117.png differ diff --git a/numbers/img_118.png b/numbers/img_118.png new file mode 100644 index 0000000000000000000000000000000000000000..30a08014e4e20a8f4af3eb8f08c8a49d769a14c8 Binary files /dev/null and b/numbers/img_118.png differ diff --git a/numbers/img_119.png b/numbers/img_119.png new file mode 100644 index 0000000000000000000000000000000000000000..8dbdcbaa0b9fec232165495bc65b40a607159812 Binary files /dev/null and b/numbers/img_119.png differ diff --git a/numbers/img_12.png b/numbers/img_12.png new file mode 100644 index 0000000000000000000000000000000000000000..d7c222858c5e6190c6eccc7c6147e14be4cd4ad2 Binary files /dev/null and b/numbers/img_12.png differ diff --git a/numbers/img_120.png b/numbers/img_120.png new file mode 100644 index 0000000000000000000000000000000000000000..948803d75720ede022a56380883866d01002c5e3 Binary files /dev/null and b/numbers/img_120.png differ diff --git a/numbers/img_121.png b/numbers/img_121.png new file mode 100644 index 0000000000000000000000000000000000000000..6fb3c1f73102d5d06b1a298a626e2261d68c3041 Binary files /dev/null and b/numbers/img_121.png differ diff --git a/numbers/img_122.png b/numbers/img_122.png new file mode 100644 index 0000000000000000000000000000000000000000..bab429a7dbcfd0867eefbff5f3cb9b2158c48863 Binary files /dev/null and b/numbers/img_122.png differ diff --git a/numbers/img_123.png b/numbers/img_123.png new file mode 100644 index 0000000000000000000000000000000000000000..4ae5387580dc0d9b459668a64fcc8339249067d4 Binary files /dev/null and b/numbers/img_123.png differ diff --git a/numbers/img_124.png b/numbers/img_124.png new file mode 100644 index 0000000000000000000000000000000000000000..b9963dff4d16e942ec6b27d23903925a944972b5 Binary files /dev/null and b/numbers/img_124.png differ diff --git a/numbers/img_125.png b/numbers/img_125.png new file mode 100644 index 0000000000000000000000000000000000000000..9dd37a26382dc98e5a05799193ea9385b17c5a80 Binary files /dev/null and b/numbers/img_125.png differ diff --git a/numbers/img_126.png b/numbers/img_126.png new file mode 100644 index 0000000000000000000000000000000000000000..2fcf2abdcf621a9a1914c302fa70118f635c72de Binary files /dev/null and b/numbers/img_126.png differ diff --git a/numbers/img_127.png b/numbers/img_127.png new file mode 100644 index 0000000000000000000000000000000000000000..ca0f21c971d7af882010c1ede0684653bc19262f Binary files /dev/null and b/numbers/img_127.png differ diff --git a/numbers/img_13.png b/numbers/img_13.png new file mode 100644 index 0000000000000000000000000000000000000000..95451114950d083069a5e6f7162604b79c24c312 Binary files /dev/null and b/numbers/img_13.png differ diff --git a/numbers/img_14.png b/numbers/img_14.png new file mode 100644 index 0000000000000000000000000000000000000000..9f393fb2b3cf020e0e75b51df3d9e44a8d760f2e Binary files /dev/null and b/numbers/img_14.png differ diff --git a/numbers/img_15.png b/numbers/img_15.png new file mode 100644 index 0000000000000000000000000000000000000000..8c4d5336f63134ac1e32b5db53f2f8673bd5a352 Binary files /dev/null and b/numbers/img_15.png differ diff --git a/numbers/img_16.png b/numbers/img_16.png new file mode 100644 index 0000000000000000000000000000000000000000..d1a2f31b8e954e877da45e0ee0562d21d3d496fb Binary files /dev/null and b/numbers/img_16.png differ diff --git a/numbers/img_17.png b/numbers/img_17.png new file mode 100644 index 0000000000000000000000000000000000000000..547d7034c436c9eebc61b8e5af32ccac62425efd Binary files /dev/null and b/numbers/img_17.png differ diff --git a/numbers/img_18.png b/numbers/img_18.png new file mode 100644 index 0000000000000000000000000000000000000000..0144355e0b172ec59c503d25792eda55f538ba8c Binary files /dev/null and b/numbers/img_18.png differ diff --git a/numbers/img_19.png b/numbers/img_19.png new file mode 100644 index 0000000000000000000000000000000000000000..5617b841e48fbca8671d28b54b7c9372c4f9ce28 Binary files /dev/null and b/numbers/img_19.png differ diff --git a/numbers/img_2.png b/numbers/img_2.png new file mode 100644 index 0000000000000000000000000000000000000000..188063d884f23acba78690c43fe5f9488fcdef67 Binary files /dev/null and b/numbers/img_2.png differ diff --git a/numbers/img_20.png b/numbers/img_20.png new file mode 100644 index 0000000000000000000000000000000000000000..60bd1cf6aac838e4827c6e91890ee32dba30cbb0 Binary files /dev/null and b/numbers/img_20.png differ diff --git a/numbers/img_21.png b/numbers/img_21.png new file mode 100644 index 0000000000000000000000000000000000000000..155e1a2af2fd6071266161f0ca1b2539b569aac5 Binary files /dev/null and b/numbers/img_21.png differ diff --git a/numbers/img_22.png b/numbers/img_22.png new file mode 100644 index 0000000000000000000000000000000000000000..f2291e7e0252cc5129efbe64a18cb570052e03fd Binary files /dev/null and b/numbers/img_22.png differ diff --git a/numbers/img_23.png b/numbers/img_23.png new file mode 100644 index 0000000000000000000000000000000000000000..0159f63ec7d98296acee9a3b340a98a904eba48b Binary files /dev/null and b/numbers/img_23.png differ diff --git a/numbers/img_24.png b/numbers/img_24.png new file mode 100644 index 0000000000000000000000000000000000000000..8130cda85969f792e8a990e4ffc7609e6ec8bd5f Binary files /dev/null and b/numbers/img_24.png differ diff --git a/numbers/img_25.png b/numbers/img_25.png new file mode 100644 index 0000000000000000000000000000000000000000..ebe62ab9107dd55a70b8ebf8fbb37ec6f2c0a567 Binary files /dev/null and b/numbers/img_25.png differ diff --git a/numbers/img_26.png b/numbers/img_26.png new file mode 100644 index 0000000000000000000000000000000000000000..c5256eb6f6f7d15500c2bb23f1aa6a7dd9eaa976 Binary files /dev/null and b/numbers/img_26.png differ diff --git a/numbers/img_27.png b/numbers/img_27.png new file mode 100644 index 0000000000000000000000000000000000000000..3e51e6617bb218307b3067ae0a11218a8b1c10c4 Binary files /dev/null and b/numbers/img_27.png differ diff --git a/numbers/img_28.png b/numbers/img_28.png new file mode 100644 index 0000000000000000000000000000000000000000..2817d4d588563e11a6cb75680d01bad02a5f9ce5 Binary files /dev/null and b/numbers/img_28.png differ diff --git a/numbers/img_29.png b/numbers/img_29.png new file mode 100644 index 0000000000000000000000000000000000000000..e6ab796b7eddfb17a4442e488cfd6f4ad3311807 Binary files /dev/null and b/numbers/img_29.png differ diff --git a/numbers/img_3.png b/numbers/img_3.png new file mode 100644 index 0000000000000000000000000000000000000000..fda3fea735e7ce49f550cde23dbc440067515820 Binary files /dev/null and b/numbers/img_3.png differ diff --git a/numbers/img_30.png b/numbers/img_30.png new file mode 100644 index 0000000000000000000000000000000000000000..5e2f2417b953ecfd92d87063c9983fc655b190bd Binary files /dev/null and b/numbers/img_30.png differ diff --git a/numbers/img_31.png b/numbers/img_31.png new file mode 100644 index 0000000000000000000000000000000000000000..f2f8e9ef766a6ff6c9d1188191c7598f13fe84ca Binary files /dev/null and b/numbers/img_31.png differ diff --git a/numbers/img_32.png b/numbers/img_32.png new file mode 100644 index 0000000000000000000000000000000000000000..da351483675d6397df95c7d42a20ad94efbb236c Binary files /dev/null and b/numbers/img_32.png differ diff --git a/numbers/img_33.png b/numbers/img_33.png new file mode 100644 index 0000000000000000000000000000000000000000..4e9d80a44fb241c98d8f6c66af75ce2e4e108c01 Binary files /dev/null and b/numbers/img_33.png differ diff --git a/numbers/img_34.png b/numbers/img_34.png new file mode 100644 index 0000000000000000000000000000000000000000..30fd2c51ec6fbe059c26acf43cb75ea0ff32f9cd Binary files /dev/null and b/numbers/img_34.png differ diff --git a/numbers/img_35.png b/numbers/img_35.png new file mode 100644 index 0000000000000000000000000000000000000000..96669926c44013898e89e49ddb5b2ee764081428 Binary files /dev/null and b/numbers/img_35.png differ diff --git a/numbers/img_36.png b/numbers/img_36.png new file mode 100644 index 0000000000000000000000000000000000000000..80bd314a9a8072d98833e1b2c39b692be74ed37f Binary files /dev/null and b/numbers/img_36.png differ diff --git a/numbers/img_37.png b/numbers/img_37.png new file mode 100644 index 0000000000000000000000000000000000000000..fe5781a64854a3c76ccdacc57b7cfd6355bfd224 Binary files /dev/null and b/numbers/img_37.png differ diff --git a/numbers/img_38.png b/numbers/img_38.png new file mode 100644 index 0000000000000000000000000000000000000000..cb68fb963c6bf78743f5aefc46236bf208656aa6 Binary files /dev/null and b/numbers/img_38.png differ diff --git a/numbers/img_39.png b/numbers/img_39.png new file mode 100644 index 0000000000000000000000000000000000000000..db3f3d109b516eb01c8a0a7054b18bf68b1f080d Binary files /dev/null and b/numbers/img_39.png differ diff --git a/numbers/img_4.png b/numbers/img_4.png new file mode 100644 index 0000000000000000000000000000000000000000..154f13485f66bdf1208c23c5ffd387d6d565d00f Binary files /dev/null and b/numbers/img_4.png differ diff --git a/numbers/img_40.png b/numbers/img_40.png new file mode 100644 index 0000000000000000000000000000000000000000..ad42f71a71ac3ea6e3a174ff31acd73c0bd8c6b5 Binary files /dev/null and b/numbers/img_40.png differ diff --git a/numbers/img_41.png b/numbers/img_41.png new file mode 100644 index 0000000000000000000000000000000000000000..26b156b45bb3532db0fad0e6ec6fe5a33599a6a2 Binary files /dev/null and b/numbers/img_41.png differ diff --git a/numbers/img_42.png b/numbers/img_42.png new file mode 100644 index 0000000000000000000000000000000000000000..a3107aee0a015e7aa42039a9f5817b431a933ba6 Binary files /dev/null and b/numbers/img_42.png differ diff --git a/numbers/img_43.png b/numbers/img_43.png new file mode 100644 index 0000000000000000000000000000000000000000..6054bd7bca9ad274fffba6ac7534fec05123e5eb Binary files /dev/null and b/numbers/img_43.png differ diff --git a/numbers/img_44.png b/numbers/img_44.png new file mode 100644 index 0000000000000000000000000000000000000000..d3243b7c2b2e6be7113b9bbefa4293b55f8da5e4 Binary files /dev/null and b/numbers/img_44.png differ diff --git a/numbers/img_45.png b/numbers/img_45.png new file mode 100644 index 0000000000000000000000000000000000000000..a7e7c59ad57109f2445dc8f14518aa5f52af0c71 Binary files /dev/null and b/numbers/img_45.png differ diff --git a/numbers/img_46.png b/numbers/img_46.png new file mode 100644 index 0000000000000000000000000000000000000000..c1a6caaa4346ee69683089bf78b4738d1efea813 Binary files /dev/null and b/numbers/img_46.png differ diff --git a/numbers/img_47.png b/numbers/img_47.png new file mode 100644 index 0000000000000000000000000000000000000000..4b0b9a3ddfa0273956227abf07333337b4214857 Binary files /dev/null and b/numbers/img_47.png differ diff --git a/numbers/img_48.png b/numbers/img_48.png new file mode 100644 index 0000000000000000000000000000000000000000..936ef1dbbf31f2901b2f13f1fc660e593b80b40e Binary files /dev/null and b/numbers/img_48.png differ diff --git a/numbers/img_49.png b/numbers/img_49.png new file mode 100644 index 0000000000000000000000000000000000000000..2338caca0931ccfb46d06711691503886f81a6c6 Binary files /dev/null and b/numbers/img_49.png differ diff --git a/numbers/img_5.png b/numbers/img_5.png new file mode 100644 index 0000000000000000000000000000000000000000..3b4812da2fd9fcad1d4aefd962afaf12a1fd863c Binary files /dev/null and b/numbers/img_5.png differ diff --git a/numbers/img_50.png b/numbers/img_50.png new file mode 100644 index 0000000000000000000000000000000000000000..5d8f39f227cfdf6bb27e01a8d8152b4d7d533049 Binary files /dev/null and b/numbers/img_50.png differ diff --git a/numbers/img_51.png b/numbers/img_51.png new file mode 100644 index 0000000000000000000000000000000000000000..70c290a76cf58bca8c8227999b97a2a246de8972 Binary files /dev/null and b/numbers/img_51.png differ diff --git a/numbers/img_52.png b/numbers/img_52.png new file mode 100644 index 0000000000000000000000000000000000000000..042b56940e0d407de296dcba0665c760cdf6573c Binary files /dev/null and b/numbers/img_52.png differ diff --git a/numbers/img_53.png b/numbers/img_53.png new file mode 100644 index 0000000000000000000000000000000000000000..81fc6d65008436297b5b7665069b241355e6aef4 Binary files /dev/null and b/numbers/img_53.png differ diff --git a/numbers/img_54.png b/numbers/img_54.png new file mode 100644 index 0000000000000000000000000000000000000000..f9fc8b311ee455a97e0105eb9ca9686fe809ef86 Binary files /dev/null and b/numbers/img_54.png differ diff --git a/numbers/img_55.png b/numbers/img_55.png new file mode 100644 index 0000000000000000000000000000000000000000..d091e39c91a19d45cb20989a07df60c7234aefe5 Binary files /dev/null and b/numbers/img_55.png differ diff --git a/numbers/img_56.png b/numbers/img_56.png new file mode 100644 index 0000000000000000000000000000000000000000..493ff518967a7ce952f591515dee45302aba7c97 Binary files /dev/null and b/numbers/img_56.png differ diff --git a/numbers/img_57.png b/numbers/img_57.png new file mode 100644 index 0000000000000000000000000000000000000000..9c03dd59125b8b57ef50c376cb0336a6db6cef23 Binary files /dev/null and b/numbers/img_57.png differ diff --git a/numbers/img_58.png b/numbers/img_58.png new file mode 100644 index 0000000000000000000000000000000000000000..b73d631558f5dfad963b36ed0a4a2ff54c820d77 Binary files /dev/null and b/numbers/img_58.png differ diff --git a/numbers/img_59.png b/numbers/img_59.png new file mode 100644 index 0000000000000000000000000000000000000000..3680011eacac2e1d79fcb397c725a4e0865822bd Binary files /dev/null and b/numbers/img_59.png differ diff --git a/numbers/img_6.png b/numbers/img_6.png new file mode 100644 index 0000000000000000000000000000000000000000..51ff2ec6a60374a921264ec18a6b0cf490e51e3e Binary files /dev/null and b/numbers/img_6.png differ diff --git a/numbers/img_60.png b/numbers/img_60.png new file mode 100644 index 0000000000000000000000000000000000000000..9523acf98a70bac2094d41232447ae146f756ec3 Binary files /dev/null and b/numbers/img_60.png differ diff --git a/numbers/img_61.png b/numbers/img_61.png new file mode 100644 index 0000000000000000000000000000000000000000..4c661c1cbdc20d0dc8748e171eed1b9642d4a58d Binary files /dev/null and b/numbers/img_61.png differ diff --git a/numbers/img_62.png b/numbers/img_62.png new file mode 100644 index 0000000000000000000000000000000000000000..fb7564bd9dbcf2004be1a4184d019ad9cf790750 Binary files /dev/null and b/numbers/img_62.png differ diff --git a/numbers/img_63.png b/numbers/img_63.png new file mode 100644 index 0000000000000000000000000000000000000000..2fcb2e65e1a8d641a4dc48504f49e7dce3543d51 Binary files /dev/null and b/numbers/img_63.png differ diff --git a/numbers/img_64.png b/numbers/img_64.png new file mode 100644 index 0000000000000000000000000000000000000000..ef4b154ee9ac60c6773d5d2c71d4618194299d2b Binary files /dev/null and b/numbers/img_64.png differ diff --git a/numbers/img_65.png b/numbers/img_65.png new file mode 100644 index 0000000000000000000000000000000000000000..32796c1419ac067ec2918bd19ca3f835f4c792f7 Binary files /dev/null and b/numbers/img_65.png differ diff --git a/numbers/img_66.png b/numbers/img_66.png new file mode 100644 index 0000000000000000000000000000000000000000..b765243f93d51ec18caead27bc8826c8debd8575 Binary files /dev/null and b/numbers/img_66.png differ diff --git a/numbers/img_67.png b/numbers/img_67.png new file mode 100644 index 0000000000000000000000000000000000000000..be92ed89850e0688d469d291d63f26007b393096 Binary files /dev/null and b/numbers/img_67.png differ diff --git a/numbers/img_68.png b/numbers/img_68.png new file mode 100644 index 0000000000000000000000000000000000000000..e36294cbd32f2ae5d8a8b411fa98e2afb2d3d2a4 Binary files /dev/null and b/numbers/img_68.png differ diff --git a/numbers/img_69.png b/numbers/img_69.png new file mode 100644 index 0000000000000000000000000000000000000000..c81a2d5958a600634b098865c8c84e25a63e1351 Binary files /dev/null and b/numbers/img_69.png differ diff --git a/numbers/img_7.png b/numbers/img_7.png new file mode 100644 index 0000000000000000000000000000000000000000..e3c3e596b285e52987869af83adac5f0d92687a7 Binary files /dev/null and b/numbers/img_7.png differ diff --git a/numbers/img_70.png b/numbers/img_70.png new file mode 100644 index 0000000000000000000000000000000000000000..5b70c94b9974ef88fa95badbe24ea53f512abedd Binary files /dev/null and b/numbers/img_70.png differ diff --git a/numbers/img_71.png b/numbers/img_71.png new file mode 100644 index 0000000000000000000000000000000000000000..d28be6537362d07eda278a511a9ff963f2da9685 Binary files /dev/null and b/numbers/img_71.png differ diff --git a/numbers/img_72.png b/numbers/img_72.png new file mode 100644 index 0000000000000000000000000000000000000000..a0d887cbfaab09ccd349ae5e8d49c604a9d28444 Binary files /dev/null and b/numbers/img_72.png differ diff --git a/numbers/img_73.png b/numbers/img_73.png new file mode 100644 index 0000000000000000000000000000000000000000..965d076c423a0947e65c31b2432182a728c5420d Binary files /dev/null and b/numbers/img_73.png differ diff --git a/numbers/img_74.png b/numbers/img_74.png new file mode 100644 index 0000000000000000000000000000000000000000..94f355e82304d4445c8d8cc6b7252723c0688944 Binary files /dev/null and b/numbers/img_74.png differ diff --git a/numbers/img_75.png b/numbers/img_75.png new file mode 100644 index 0000000000000000000000000000000000000000..3cdc8adf591b248a660bbdbbfca7f6cb09b7652b Binary files /dev/null and b/numbers/img_75.png differ diff --git a/numbers/img_76.png b/numbers/img_76.png new file mode 100644 index 0000000000000000000000000000000000000000..f56e2d312815c8d6902ae489adc0d9d4389f259f Binary files /dev/null and b/numbers/img_76.png differ diff --git a/numbers/img_77.png b/numbers/img_77.png new file mode 100644 index 0000000000000000000000000000000000000000..687fe07066188e2f5a14e2f76ff7974c08899edc Binary files /dev/null and b/numbers/img_77.png differ diff --git a/numbers/img_78.png b/numbers/img_78.png new file mode 100644 index 0000000000000000000000000000000000000000..47ee3c10869a0cad7a12bff8b7c49bebcda4e458 Binary files /dev/null and b/numbers/img_78.png differ diff --git a/numbers/img_79.png b/numbers/img_79.png new file mode 100644 index 0000000000000000000000000000000000000000..5666b1fcd1de8157e79b52d123c7eb7707bd6b1d Binary files /dev/null and b/numbers/img_79.png differ diff --git a/numbers/img_8.png b/numbers/img_8.png new file mode 100644 index 0000000000000000000000000000000000000000..ac231e8ecca821326331c4e9a75a86b271291f6d Binary files /dev/null and b/numbers/img_8.png differ diff --git a/numbers/img_80.png b/numbers/img_80.png new file mode 100644 index 0000000000000000000000000000000000000000..169d63c340e7ac5a6cf4eb12032dd9395e87486b Binary files /dev/null and b/numbers/img_80.png differ diff --git a/numbers/img_81.png b/numbers/img_81.png new file mode 100644 index 0000000000000000000000000000000000000000..98756cc34f5336a9a150da7f44457ff4744868d2 Binary files /dev/null and b/numbers/img_81.png differ diff --git a/numbers/img_82.png b/numbers/img_82.png new file mode 100644 index 0000000000000000000000000000000000000000..10b78821dbd8292b391e21b73d16991caf6b5e76 Binary files /dev/null and b/numbers/img_82.png differ diff --git a/numbers/img_83.png b/numbers/img_83.png new file mode 100644 index 0000000000000000000000000000000000000000..38fc7113d8f09842e78d8da7e561f85c7457ab47 Binary files /dev/null and b/numbers/img_83.png differ diff --git a/numbers/img_84.png b/numbers/img_84.png new file mode 100644 index 0000000000000000000000000000000000000000..a1ccf603b357d6da2b295afaa5ac961b7e911227 Binary files /dev/null and b/numbers/img_84.png differ diff --git a/numbers/img_85.png b/numbers/img_85.png new file mode 100644 index 0000000000000000000000000000000000000000..5822a9ab859d63c6cc181b71ce4bdb0eefd7c621 Binary files /dev/null and b/numbers/img_85.png differ diff --git a/numbers/img_86.png b/numbers/img_86.png new file mode 100644 index 0000000000000000000000000000000000000000..bfaf0b60a79043cea6833c30912715d17b1e62f8 Binary files /dev/null and b/numbers/img_86.png differ diff --git a/numbers/img_87.png b/numbers/img_87.png new file mode 100644 index 0000000000000000000000000000000000000000..b9dd3e47e254501671058b7ac880e19eb57d413d Binary files /dev/null and b/numbers/img_87.png differ diff --git a/numbers/img_88.png b/numbers/img_88.png new file mode 100644 index 0000000000000000000000000000000000000000..c5daab51734a39273fd194f54aef59684d9ac343 Binary files /dev/null and b/numbers/img_88.png differ diff --git a/numbers/img_89.png b/numbers/img_89.png new file mode 100644 index 0000000000000000000000000000000000000000..7a5d979a2d18aaea587e4913a59e2b61313026f7 Binary files /dev/null and b/numbers/img_89.png differ diff --git a/numbers/img_9.png b/numbers/img_9.png new file mode 100644 index 0000000000000000000000000000000000000000..9e2179150a0805cb591502569ecf913f9b179d43 Binary files /dev/null and b/numbers/img_9.png differ diff --git a/numbers/img_90.png b/numbers/img_90.png new file mode 100644 index 0000000000000000000000000000000000000000..62b71cf955fccd3e3ddb1996348450c0f6064dcf Binary files /dev/null and b/numbers/img_90.png differ diff --git a/numbers/img_91.png b/numbers/img_91.png new file mode 100644 index 0000000000000000000000000000000000000000..99533b7da21d566f7ee8cb659e95be1901c76680 Binary files /dev/null and b/numbers/img_91.png differ diff --git a/numbers/img_92.png b/numbers/img_92.png new file mode 100644 index 0000000000000000000000000000000000000000..80bb32a802f175b812e56b2513bb47032dee4996 Binary files /dev/null and b/numbers/img_92.png differ diff --git a/numbers/img_93.png b/numbers/img_93.png new file mode 100644 index 0000000000000000000000000000000000000000..0540cdf970304dc0612122ee6737a67f44291e04 Binary files /dev/null and b/numbers/img_93.png differ diff --git a/numbers/img_94.png b/numbers/img_94.png new file mode 100644 index 0000000000000000000000000000000000000000..075732a57bbc749659bbb75258265384015bf457 Binary files /dev/null and b/numbers/img_94.png differ diff --git a/numbers/img_95.png b/numbers/img_95.png new file mode 100644 index 0000000000000000000000000000000000000000..eb318b7253a2d1436d84ad6f2bbdca869a71cf93 Binary files /dev/null and b/numbers/img_95.png differ diff --git a/numbers/img_96.png b/numbers/img_96.png new file mode 100644 index 0000000000000000000000000000000000000000..1bebfb20ad30a3450617f51b352d0ab71721e93d Binary files /dev/null and b/numbers/img_96.png differ diff --git a/numbers/img_97.png b/numbers/img_97.png new file mode 100644 index 0000000000000000000000000000000000000000..59e927d8a7886f3c844e25e421c412560aee8007 Binary files /dev/null and b/numbers/img_97.png differ diff --git a/numbers/img_98.png b/numbers/img_98.png new file mode 100644 index 0000000000000000000000000000000000000000..9e7ee049994fbd2a98996ce804c066ab6522769f Binary files /dev/null and b/numbers/img_98.png differ diff --git a/numbers/img_99.png b/numbers/img_99.png new file mode 100644 index 0000000000000000000000000000000000000000..119595e6509421d31fb9198fa44e72043d346bbb Binary files /dev/null and b/numbers/img_99.png differ diff --git a/train.py b/train.py new file mode 100644 index 0000000000000000000000000000000000000000..9e3b9990bc823c2fe483498680eb0bf908853cbd --- /dev/null +++ b/train.py @@ -0,0 +1,135 @@ +import os +import torch +import lightning as pl +from torchinfo import summary + +from lightning.pytorch import loggers as pl_loggers +from functorch.compile import compiled_function,draw_graph +from lightning.pytorch.profilers import PyTorchProfiler +from lightning.pytorch.callbacks import ( + DeviceStatsMonitor, + EarlyStopping, + LearningRateMonitor, + ModelCheckpoint, + ModelPruning +) +from lightning.pytorch.callbacks.progress import TQDMProgressBar + + +from data import LitMNISTDataModule +from config import CONFIG +from model import LitMNISTModel +from utils import TRAIN_TRANSFORMS, TEST_TRANSFORMS + + +# Auxilary utils +torch.set_float32_matmul_precision('high') +torch.cuda.amp.autocast(enabled=True,dtype=torch.float32) +device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu') +torch.set_default_device( device= device ) +torch.cuda.empty_cache() +# pl.seed_everything(123, workers=True) + + +## Loggers +logger:pl_loggers.TensorBoardLogger = pl_loggers.TensorBoardLogger(save_dir='logs/',name= "lightning_logs",log_graph=True) + +## CallBacks +call_backs = [ + TQDMProgressBar(refresh_rate=10), + ModelCheckpoint( + monitor="val/loss", dirpath=os.path.join('logs','chkpoints'), filename="{epoch:02d}",save_top_k=1, + ), + DeviceStatsMonitor(cpu_stats=True), + # EarlyStopping(monitor="val/loss",mode='min'), + LearningRateMonitor(logging_interval='step') +] + +## Profilers +perf_dir = os.path.join(os.path.dirname(__file__),'logs','profiler') +perf_profiler =PyTorchProfiler( + dirpath=perf_dir, + filename="perf_logs_pytorch", + group_by_input_shapes=True, + emit_nvtx=torch.cuda.is_available(), + activities=( + [ + torch.profiler.ProfilerActivity.CPU, + torch.profiler.ProfilerActivity.CUDA, + ] + if torch.cuda.is_available() + else [ + torch.profiler.ProfilerActivity.CPU, + ] + ), + schedule=torch.profiler.schedule( + wait=1, warmup=1, active=5, repeat=3, skip_first=True + ), + profile_memory=True, + with_stack=True, + with_flops=True, + with_modules=True, + on_trace_ready=torch.profiler.tensorboard_trace_handler(str( os.path.join(perf_dir,'trace')) ), + ) + + + +## MNISTDataModule +dm = LitMNISTDataModule( + data_dir=CONFIG['data'].get('dir_path','.'), + batch_size= CONFIG.get('batch_size'), + num_workers=CONFIG.get('num_workers'), + test_transform=TEST_TRANSFORMS, + train_transform=TRAIN_TRANSFORMS + ) +dm.prepare_data() +dm.setup() + +## MNISTModel +model = LitMNISTModel() +# model = LitMNISTModel.load_from_checkpoint(r'C:\Users\muthu\GitHub\Spaces 🚀\UnSolvedMNIST\logs\chkpoints\epoch=04.ckpt') + +# Single BATCH +batch = next(iter(dm.train_dataloader())) +# Computational graph +model.example_input_array = batch[0] +# CPU Stats +with torch.autograd.profiler.profile() as prof: + output = model.to(device)(batch[0].to(device)) + +os.makedirs(name=os.path.join(os.path.dirname(__file__),'logs','profiler'),exist_ok=True) +with open(os.path.join(os.path.dirname(__file__),'logs','profiler',"cpu_throttle.txt"), "w") as text_file: + text_file.write(f"{prof.key_averages().table(sort_by='self_cpu_time_total',top_level_events_only=False)}") +# Model Summary +summary( + model, + input_size=batch[0].shape, + depth=5, + verbose=2, + col_width=16, + col_names=[ + "input_size", + "output_size", + "num_params", + "kernel_size", + "mult_adds", + ], + row_settings=["var_names"], + ) + + +## Trainer +trainer = pl.Trainer( + max_epochs=CONFIG['training'].get('num_epochs',15), + logger=logger, + profiler=perf_profiler, + callbacks=call_backs, + precision=32, + enable_model_summary=False, + enable_progress_bar=True, + ) + +## Training +trainer.fit(model=model,datamodule=dm) +## Validation +trainer.validate(model,datamodule=dm) \ No newline at end of file diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5bff5509e14e93eada743eddeb4051784d1e3f --- /dev/null +++ b/utils/__init__.py @@ -0,0 +1,3 @@ +# from .utils import plot_3d,simulate_loss_curvature + +from .utils import TRAIN_TRANSFORMS, TEST_TRANSFORMS \ No newline at end of file diff --git a/utils/utils.py b/utils/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..843449f920c9957db702ee084a592f0a5f5ef81a --- /dev/null +++ b/utils/utils.py @@ -0,0 +1,33 @@ +# from lightning.pytorch.utilities.types import TRAIN_DATALOADERS,EVAL_DATALOADERS +# def calculate_mean_std_mnist(datamodule:pl.LightningDataModule): +# data_loader:TRAIN_DATALOADERS; +# mean = torch.zeros(1); +# std = torch.zeros(1) +# num_samples = 0 +# for img in data_loader: +# image = img[0] +# image = image.squeeze() +# mean += image.mean() # mean across channel sum for all pics +# std += image.std() +# num_samples += 1 + +# mean /= num_samples +# std /= num_samples +# return (mean.item(),std.item()) + + +from torchvision import transforms + +TRAIN_TRANSFORMS = transforms.Compose([ + transforms.RandomApply([transforms.CenterCrop(22), ], p=0.1), + transforms.RandomAffine(degrees=7, shear=10, translate=(0.1, 0.1), scale=(0.8, 1.2)), + transforms.Resize((28, 28)), + transforms.ToTensor(), + transforms.Normalize((0.1307,), (0.3081,)), + ]) + + +TEST_TRANSFORMS = transforms.Compose([ + transforms.ToTensor(), + transforms.Normalize((0.1307,), (0.3081,)) + ]) \ No newline at end of file