Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yw.lee committed Mar 24, 2021
1 parent f23f351 commit a645b56
Show file tree
Hide file tree
Showing 13 changed files with 1,534 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

weights/*
!weights/.gitkeep
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
# PlaidML-CPUvsGPU
PyQT5 based GUI application for performance comparison between Tensorflow (CPU) and PlaidML (GPU)

![demoUI](images/ui.png)

### Environment

CPU : Intel i7-8086K
GPU : Gigabyte Radeon RX Vega 64 Silver HBM2 8GB

OS : Ubuntu 18.04
Driver : AMD-GPUPRO 18.20

Python 3.5
Keras 2.2.2
Tensorflow 1.10
PlaidML 0.3.5

### Usage

We used SSD (single shot multibox detector) model for internal object detection algorithm.
Also, we were able to develop this application with a lot of inspiration from the repository below.

Download the pre-trained weights from [ssd_kerasV2](https://github.com/tanakataiki/ssd_kerasV2) named `VGG16SSD300weights_voc_2007_class20.hdf5`
Save the weight file in the `weight` directory.

Create anaconda environment using `environment.yml` and following command:
```
$ conda env create
```

Activate virtual envitonment and start the application
```
$ conda activate demo
(demo) $ python main.py
```
226 changes: 226 additions & 0 deletions demo.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1241</width>
<height>542</height>
</rect>
</property>
<property name="windowTitle">
<string>Demo</string>
</property>
<property name="locale">
<locale language="Korean" country="SouthKorea"/>
</property>
<widget class="QPushButton" name="pb_start">
<property name="geometry">
<rect>
<x>830</x>
<y>40</y>
<width>121</width>
<height>71</height>
</rect>
</property>
<property name="text">
<string>Start</string>
</property>
</widget>
<widget class="QTextEdit" name="te_info">
<property name="geometry">
<rect>
<x>690</x>
<y>220</y>
<width>261</width>
<height>311</height>
</rect>
</property>
</widget>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>661</width>
<height>521</height>
</rect>
</property>
<property name="title">
<string>View</string>
</property>
<widget class="QWidget" name="widget_view" native="true">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>640</width>
<height>480</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>640</width>
<height>480</height>
</size>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
</widget>
</widget>
<widget class="QComboBox" name="cb_device">
<property name="geometry">
<rect>
<x>690</x>
<y>40</y>
<width>131</width>
<height>31</height>
</rect>
</property>
<item>
<property name="text">
<string>GPU</string>
</property>
</item>
<item>
<property name="text">
<string>CPU</string>
</property>
</item>
</widget>
<widget class="QComboBox" name="cb_model">
<property name="geometry">
<rect>
<x>690</x>
<y>100</y>
<width>131</width>
<height>31</height>
</rect>
</property>
<item>
<property name="text">
<string>VGG-16</string>
</property>
</item>
<item>
<property name="text">
<string>MonileNet</string>
</property>
</item>
</widget>
<widget class="QComboBox" name="cb_source">
<property name="geometry">
<rect>
<x>690</x>
<y>160</y>
<width>131</width>
<height>31</height>
</rect>
</property>
<item>
<property name="text">
<string>Camera</string>
</property>
</item>
<item>
<property name="text">
<string>Video File</string>
</property>
</item>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>690</x>
<y>20</y>
<width>67</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Device :</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>690</x>
<y>140</y>
<width>67</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Source :</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>690</x>
<y>80</y>
<width>67</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Model :</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>690</x>
<y>200</y>
<width>101</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Information</string>
</property>
</widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>960</x>
<y>10</y>
<width>271</width>
<height>521</height>
</rect>
</property>
<property name="title">
<string>Performance</string>
</property>
<widget class="QWidget" name="widget_perf" native="true">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>251</width>
<height>481</height>
</rect>
</property>
</widget>
</widget>
<widget class="QPushButton" name="pb_stop">
<property name="geometry">
<rect>
<x>830</x>
<y>120</y>
<width>121</width>
<height>71</height>
</rect>
</property>
<property name="text">
<string>Stop</string>
</property>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
36 changes: 36 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: demo
channels:
- defaults
dependencies:
- freeglut=3.0.0
- freetype=2.9.1
- gstreamer=1.14.0
- harfbuzz=1.8.8
- hdf5=1.10.2
- matplotlib=3.0.1
- numpy=1.15.4
- opencv=3.4.2
- pillow=5.3.0
- pip=18.1
- pyqt=5.9.2
- python=3.6.6
- qt=5.9.6
- scikit-learn=0.20.0
- scipy=1.1.0
- send2trash=1.5.0
- setuptools=40.5.0
- sip=4.19.8
- six=1.11.0
- sqlite=3.25.2
- tqdm=4.28.1
- pip:
- h5py==2.8.0
- keras==2.2.2
- keras-applications==1.0.4
- keras-preprocessing==1.0.2
- plaidbench==0.3.5
- plaidml-keras==0.3.5
- protobuf==3.6.1
- pygame==1.9.4
- tensorflow==1.12

Binary file added images/ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from PyQt5 import QtWidgets
from window import Window
from multiprocessing import Process, Queue
import multiprocessing as mp
import tensorflow as tf
import sys
import os

def inference(is_gpu, input_q, output_q):
pid = os.getpid()
with tf.Graph().as_default():
with tf.Session().as_default():
if is_gpu:
print('GPU(PlaidML)-Process ID: %d' % (pid))
import ssd
model = ssd.Model(True)
else :
print('CPU(Tensorflow)-Process ID: %d' % (pid))
import ssd
model = ssd.Model(False)

while True:
if not input_q.empty():
image = input_q.get()
result, time = model.inference(image)

if output_q.qsize() <= 10:
output_q.put((result, time))
else:
continue

def main():
try:
### Process
cin = Queue()
cout = Queue()
gin = Queue()
gout = Queue()

gpu_proc = Process(target=inference, args=(True, gin, gout))
cpu_proc = Process(target=inference, args=(False, cin, cout))

gpu_proc.start()
cpu_proc.start()

app = QtWidgets.QApplication(sys.argv)
DemoGUI = Window(cin, gin, cout, gout, cpu_proc, gpu_proc, None)
DemoGUI.setWindowTitle('Demo')
DemoGUI.show()
app.exec_()

finally:
os.kill(gpu_proc.pid, 15)
os.kill(cpu_proc.pid, 15)

if __name__ == "__main__":
mp.set_start_method('spawn')
main()
Loading

0 comments on commit a645b56

Please sign in to comment.