Package: building-inspection-toolkit
Building Inspection ToolkitBuilding Inspection Toolkithelps you with machine learning projects in the field of damage recognition on built structures, currenlty with a focus on bridges.DataHub: It contains currated open-source datasets, with fix train/val/test splits (as this is often missing) and cleaned annotations. It is build forPyTorch.Metrics: We define useful metrics you can use and report to make comparability easier.Pre-trained Models: We provide strong baseline models for different datasets. Seebikit-modelsfor more details.The DatasetsOpen-source dataNameTypeUnique imagestrain/val/test splitCDS[Web]2-class single-target Clf1,028bikit-versionBCD[Paper][Data]2-class single-target Clf6069modified-versionSDNET[Web]2-class single-target Clf56,092bikit-versionMCDS[Paper][Data]8-class multi-target Clf2,612bikit-versionCODEBRIM[Paper][Data]6-class multi-target Clf7,730original-versionBikit datasetsDifferent versionsFor some datasets different versions exists. This may be due to the fact that the authors already provide different version (e.g. CODEBRIM) or other authors update datasets (e.g. Bukhsh for MCDS).SplitsWe provide carefully selectedtrain/val/testsplits. We introduce splits, when they are not available or update splits where we think this is useful.OverviewnameNotecdsOriginal datasetwith bikit'strain/val/testsplitsbcdOriginal datasetwith modifiedtrain/val/testsplits (original train was splitted intotrain/val)sdnetOriginal datasetwith bikit'strain/val/testsplits; Many wrong labelssdnet_binaryMany wrong labels; Binarized version of sdnet: crack, no cracksdnet_bikitCleaned wrong labelssdnet_bikit_binaryCleaned wrong labels; Binarized version of sdnet: crack, no crackmcds_BukhshBukhsh et al. create a 10-class dataset out of the 3-step dataset from Hüthwohl et al. (with same wrong labels); With bikit'strain/val/testsplitsmcds_bikitWe create a 8-class dataset from Hüthwohl et al. which prevent wrong labels with bikit'strain/val/testsplits.codebrim-classif-balancedOriginal datasetwith originaltrain/val/testsplits: Underrepresented classes are oversampled.codebrim-classifOriginal datasetwith originaltrain/val/testsplits.meta36-class multi-target dataset based on bcd, codebrim-classif, and mcds_bikit.meta46-class multi-target dataset based on bcd, codebrim-classif, mcds_bikit, and sdnet_bikit_binary.UsageDataList and download datafrombikit.utilsimportlist_datasets,download_dataset# List all datasetslist_datasets()# Download datadownload_dataset("<name>")UseBikitDatasetfrombikit.utilsimportdownload_datasetfrombikit.datasetsimportBikitDataset# Deprecated: from bikit.datasets.data import BikitDatasetfromtorch.utils.dataimportDataLoaderfromtorchvisionimporttransforms# Select a dataset:name="mcds_bikit"download_dataset(name)# equals to `download_dataset("mcds_Bukhsh")`my_transform=transforms.Compose([transforms.Resize((256,256)),transforms.ToTensor()])# Use return_type 'pt' (default) or 'np'train_dataset=BikitDataset(name,split="train",transform=my_transform,return_type="pt")train_loader=DataLoader(dataset=train_dataset,batch_size=64,shuffle=False,num_workers=0)# Use it in your training loopfori,(imgs,labels)inenumerate(train_dataset):print(i,imgs.shape,labels.shape)breakMetricsFor single-target problems (likecds,bcd,sdnet_bikit_binary) metrics will follow (#TODO).For multi-target problems (likesdnet_bikit,mcds_bikitormeta3) we useExact Match Ratio(EMR_mt) andclasswise Recall(Recalls_mt).#!pip install torchmetricsfrombikit.metricsimportEMR_mt,Recalls_mtmyemr=EMR_mt(use_logits=False)myrecalls=Recalls_mt()# fake datapreds0=torch.tensor([[.9,0.1,0.9,0.1,0.9,0.1],[.8,0.2,0.9,0.2,0.9,0.2],[.7,0.9,0.2,0.2,0.2,0.2]])preds1=torch.tensor([[.0,0.1,0.9,0.1,0.9,0.1],[.8,0.2,0.9,0.2,0.9,0.2],[.7,0.9,0.2,0.9,0.2,0.9]])target=torch.tensor([[1,0,1,0,0,1],[1,1,0,0,1,0],[1,1,0,1,0,1]])# batch 0myemr(preds0,target),myrecalls(preds0,target)print(myemr.compute(),myrecalls.compute())# batch 1myemr(preds1,target),myrecalls(preds1,target)print(myemr.compute(),myrecalls.compute())# Reset at end of epochmyemr.reset(),myrecalls.reset()print(myemr,myrecalls)ModelsList modelsfrombikit.utilsimportlist_models# List all modelslist_models()# Download and load modelmodel,metadata=load_model("MCDS_ResNet50")Model Inferencefrombikit.utilsimportload_model,get_metadata,load_img_from_urlfrombikit.modelsimportmake_predictionimg=load_img_from_url("https://github.com/phiyodr/building-inspection-toolkit/raw/master/bikit/data/11_001990.jpg")model,metadata=load_model("MCDS_ResNet50",add_metadata=True)prob,pred=make_prediction(model,img,metadata,print_predictions=True,preprocess_image=True)#> Crack                [██████████████████████████████████████  ]  95.86%#> Efflorescence        [                                        ]   0.56%#> ExposedReinforcement [                                        ]   0.18%#> General              [                                        ]   0.60%#> NoDefect             [                                        ]   1.29%#> RustStaining         [                                        ]   0.44%#> Scaling              [                                        ]   0.05%#> Spalling             [                                        ]   0.85%#> Inference time (CPU): 44.26 msMiscPyTestInstall dependencies firstpip3install-U-rrequirements.txt-rtest_requirements.txtRun PyTest# cd bridge-inspection-toolkit/pytestCitationUse the "Cite this repository" tool in theAboutsection of this repo to cite us :)