├── .gitmodules ├── pklot.py ├── README.md └── main.py /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "pyffe"] 2 | path = pyffe 3 | url = https://github.com/fabiocarrara/pyffe 4 | -------------------------------------------------------------------------------- /pklot.py: -------------------------------------------------------------------------------- 1 | import pyffe 2 | from pyffe.models import mAlexNet 3 | 4 | PKLot = pyffe.Dataset('splits/PKLot') 5 | 6 | input_format = pyffe.InputFormat( 7 | new_width=256, 8 | new_height=256, 9 | crop_size=224, 10 | scale=1. / 256, 11 | mirror=True 12 | ) 13 | 14 | model = mAlexNet(input_format, num_output=2, batch_sizes=[64, 100]) 15 | 16 | solver = pyffe.Solver( 17 | base_lr=0.01, 18 | train_epochs=18, 19 | lr_policy="step", 20 | gamma=0.5, 21 | stepsize_epochs=6, 22 | val_interval_epochs=0.5, 23 | val_epochs=0.05, 24 | display_per_epoch=30, 25 | snapshot_interval_epochs=0.5 26 | ) 27 | exps = [ 28 | # original PKLot experiments, single camera training 29 | pyffe.Experiment(model, solver, PKLot.UFPR05_train, val=[PKLot.UFPR04_train, PKLot.UFPR05_train, PKLot.PUC_train], test=[PKLot.UFPR04_test, PKLot.UFPR05_test, PKLot.PUC_test]), 30 | pyffe.Experiment(model, solver, PKLot.UFPR04_train, val=[PKLot.UFPR04_train, PKLot.UFPR05_train, PKLot.PUC_train], test=[PKLot.UFPR04_test, PKLot.UFPR05_test, PKLot.PUC_test]), 31 | pyffe.Experiment(model, solver, PKLot.PUC_train, val=[PKLot.UFPR04_train, PKLot.UFPR05_train, PKLot.PUC_train], test=[PKLot.UFPR04_test, PKLot.UFPR05_test, PKLot.PUC_test]), 32 | ] 33 | 34 | for exp in exps: 35 | exp.setup('runs_pklot/') 36 | 37 | for exp in exps: 38 | exp.run(plot=False) 39 | 40 | pyffe.summarize(exps).to_csv('pklot_results.csv') 41 | 42 | 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deep Learning for Decentralized Parking Lot Occupancy Detection 2 | 3 | This repo contains code to reproduce the experiments presented in [Deep Learning for Decentralized Parking Lot Occupancy Detection](https://www.sciencedirect.com/science/article/pii/S095741741630598X). 4 | 5 | Visit the [project website](http://cnrpark.it/) for more info and resources (dataset, pre-trained models). 6 | 7 | ## Requirements 8 | 9 | - Caffe with Python interface (PyCaffe) 10 | 11 | ## Steps to reproduce experiments 12 | 13 | 1. Clone this repo together with its submodules: 14 | 15 | ```bash 16 | git clone --recursive https://github.com/fabiocarrara/deep-parking.git 17 | ``` 18 | 19 | 2. Download the datasets using the following links and extract them somewhere. 20 | 21 | | Dataset | Link | Size | 22 | | ------- | ---- | ---: | 23 | | CNRPark | http://cnrpark.it/dataset/CNRPark-Patches-150x150.zip | 36.6 MB | 24 | | CNR-EXT | http://cnrpark.it/dataset/CNR-EXT-Patches-150x150.zip | 449.5 MB | 25 | | PKLot | visit [PKLot webpage](https://web.inf.ufpr.br/vri/databases/parking-lot-database/) | 4.6 GB | 26 | 27 | 28 | 3. Get the dataset splits and extract them in the repo folder 29 | ```bash 30 | # Listfile containing dataset splits 31 | wget http://cnrpark.it/dataset/splits.zip 32 | unzip splits.zip 33 | ``` 34 | 35 | 4. Add a `config.py` files inside each folder in `splits/` to tell `pyffe` where the images are. 36 | The content of the files should be like this (adjust the `root_dir` attribute to the absolute path of the extracted datasets): 37 | ```python 38 | config = dict(root_folder = '/path/to/dataset/dir/') 39 | ``` 40 | This path will be prepended to each line in the list files defining the various splits. 41 | 42 | 43 | 5. Train and evaluate all the models by running: 44 | ```bash 45 | python main.py 46 | ``` 47 | Modify `main.py` to select the experiments you want to reproduce. 48 | Run `pklot.py` if you want to train and evaluate our architecture on the PKLot splits only. 49 | 50 | ## Citation 51 | 52 | ``` 53 | @article{amato2017deep, 54 | title={Deep learning for decentralized parking lot occupancy detection}, 55 | author={Amato, Giuseppe and Carrara, Fabio and Falchi, Fabrizio and Gennaro, Claudio and Meghini, Carlo and Vairo, Claudio}, 56 | journal={Expert Systems with Applications}, 57 | volume={72}, 58 | pages={327--334}, 59 | year={2017}, 60 | publisher={Pergamon} 61 | } 62 | ``` 63 | 64 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import pyffe 2 | from pyffe.models import mAlexNet, AlexNet 3 | 4 | dataset_prefix = 'splits' 5 | 6 | PKLot = pyffe.Dataset(dataset_prefix + '/PKLot') 7 | CNRParkAB = pyffe.Dataset(dataset_prefix + '/CNRParkAB') 8 | CNRExt = pyffe.Dataset(dataset_prefix + '/CNRPark-EXT') 9 | Combined = pyffe.Dataset(dataset_prefix + '/Combined') 10 | 11 | input_format = pyffe.InputFormat( 12 | new_width=256, 13 | new_height=256, 14 | crop_size=224, 15 | scale=1. / 256, 16 | mirror=True 17 | ) 18 | 19 | model = mAlexNet(input_format, num_output=2, batch_sizes=[64, 100]) 20 | bigmodel = AlexNet(input_format, num_output=2, batch_sizes=[64, 50]) 21 | 22 | solver = pyffe.Solver( 23 | base_lr=0.0008, 24 | train_epochs=6, 25 | lr_policy="step", 26 | gamma=0.75, 27 | stepsize_epochs=2, 28 | val_interval_epochs=0.15, 29 | val_epochs=0.1, 30 | display_per_epoch=30, 31 | snapshot_interval_epochs=0.15, 32 | ) 33 | exps = [ 34 | # exp 1.1 and 1.2 35 | pyffe.Experiment(model, solver, PKLot.train, val=[PKLot.val, CNRExt.val], test=[PKLot.test, CNRExt.test]), 36 | pyffe.Experiment(bigmodel, solver, PKLot.train, val=[PKLot.val, CNRExt.val], test=[PKLot.test, CNRExt.test]), 37 | 38 | # exp 2.1 and 2.2 39 | pyffe.Experiment(model, solver, CNRParkAB.all, val=[CNRExt.val, PKLot.val], test=[CNRExt.test, PKLot.test]), 40 | pyffe.Experiment(bigmodel, solver, CNRParkAB.all, val=[CNRExt.val, PKLot.val], test=[CNRExt.test, PKLot.test]), 41 | 42 | # exp 3.1 and 3.2 43 | pyffe.Experiment(model, solver, Combined.CNRParkAB_Ext_train, val=[CNRExt.val, PKLot.val], test=[CNRExt.test, PKLot.test] ), 44 | pyffe.Experiment(bigmodel, solver, Combined.CNRParkAB_Ext_train, val=[CNRExt.val, PKLot.val], test=[CNRExt.test, PKLot.test] ), 45 | 46 | # exp 4.1 and 4.2 47 | pyffe.Experiment(model, solver, Combined.CNRParkAB_Ext_train_C1C8, val=[CNRExt.val, PKLot.val], test=[CNRExt.test, PKLot.test] ), 48 | pyffe.Experiment(bigmodel, solver, Combined.CNRParkAB_Ext_train_C1C8, val=[CNRExt.val, PKLot.val], test=[CNRExt.test, PKLot.test] ), 49 | 50 | # Inter-weather experiments 51 | pyffe.Experiment(model, solver, CNRExt.sunny, val=[CNRExt.overcast, CNRExt.rainy, PKLot.val], test=[CNRExt.overcast, CNRExt.rainy, PKLot.test]), 52 | pyffe.Experiment(model, solver, CNRExt.overcast, val=[CNRExt.sunny, CNRExt.rainy, PKLot.val], test=[CNRExt.sunny, CNRExt.rainy, PKLot.test]), 53 | pyffe.Experiment(model, solver, CNRExt.rainy, val=[CNRExt.sunny, CNRExt.overcast, PKLot.val], test=[CNRExt.sunny, CNRExt.overcast, PKLot.test]), 54 | 55 | # Inter-camera experiments 56 | pyffe.Experiment(model, solver, CNRExt.camera8, 57 | val=[CNRExt.camera1, 58 | CNRExt.camera2, 59 | CNRExt.camera3, 60 | CNRExt.camera4, 61 | CNRExt.camera5, 62 | CNRExt.camera6, 63 | CNRExt.camera7, 64 | PKLot.val, 65 | CNRExt.camera9], 66 | test=[CNRExt.camera1, 67 | CNRExt.camera2, 68 | CNRExt.camera3, 69 | CNRExt.camera4, 70 | CNRExt.camera5, 71 | CNRExt.camera6, 72 | CNRExt.camera7, 73 | PKLot.test, 74 | CNRExt.camera9]), 75 | 76 | pyffe.Experiment(model, solver, CNRExt.camera1, 77 | val=[PKLot.val, 78 | CNRExt.camera2, 79 | CNRExt.camera3, 80 | CNRExt.camera4, 81 | CNRExt.camera5, 82 | CNRExt.camera6, 83 | CNRExt.camera7, 84 | CNRExt.camera8, 85 | CNRExt.camera9], 86 | test=[PKLot.test, 87 | CNRExt.camera2, 88 | CNRExt.camera3, 89 | CNRExt.camera4, 90 | CNRExt.camera5, 91 | CNRExt.camera6, 92 | CNRExt.camera7, 93 | CNRExt.camera8, 94 | CNRExt.camera9]), 95 | ] 96 | 97 | for exp in exps: 98 | exp.setup('runs/') 99 | exp.run(plot=False) # run without live plot 100 | 101 | pyffe.summarize(exps).to_csv('results.csv') 102 | 103 | 104 | --------------------------------------------------------------------------------