Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Using Android Things to Detect & Exterminate Reptilians

788 views

Published on

Using Android Things to Detect & Exterminate Reptilians

Published in: Technology
  • Be the first to comment

Using Android Things to Detect & Exterminate Reptilians

  1. 1. Using Android Things to Detect & Exterminate Reptilians
  2. 2. Android is EVERYWHERE (01) (01) Reptilians too are everywhere, but they suck.
  3. 3. Android Things
  4. 4. "If you can build an app, you can build a device!"
  5. 5. 8-bit Distributed Piano (02) (02) https://riggaroo.co.za/android-things-building-distributed-piano/
  6. 6. Play Music Like a Scientist
  7. 7. Beer Can Music Player (03) (03) http://nilhcem.com/android-things/discovering-the-I2C-api-creating-a-capacitive-sensor-driver
  8. 8. Notification Cat (04) (04) http://nilhcem.com/android-things/bluetooth-low-energy
  9. 9. Google Assistant powered Robot (05) (05) http://nilhcem.com/android-things/create-your-google-assistant-robots
  10. 10. OK, BUT, WHY? I mean... I can use an Arduino too
  11. 11. Perfect for • Doing some computation locally • Using Google Services • A secure platform • Prototype and production
  12. 12. Perfect for • Doing some computation locally • Using Google Services • A secure platform • Prototype and production
  13. 13. Perfect for • Doing some computation locally • Using Google Services • A secure platform • Prototype and production
  14. 14. Perfect for • Doing some computation locally • Using Google Services • A secure platform • Prototype and production
  15. 15. Compatible boards (06) • Raspberry Pi 3 • NXP i.MX7D/i.MX6UL • Intel Edison/Joule (discontinued) (06) https://developer.android.com/things/hardware/developer-kits.html
  16. 16. Raspberry Pi 3 - NXP i.MX7D
  17. 17. SOM (System on module)
  18. 18. SOM (System on module)
  19. 19. Edison Candle (07) (07) https://github.com/androidthings/edison-candle
  20. 20. SOMs are pre-certified for regulator approvals
  21. 21. Perfect for • Doing some computation locally • Using Google Services • A secure platform • Prototype and production
  22. 22. Facts • Humans don't use their brain to its full capacity • Humans are distracted by media, entertainment, and politics. • Borders, country lines lead to endless wars and conflicts
  23. 23. Reason?
  24. 24. REPTILIANS
  25. 25. Reptilian conspiracy theory (08) (08) https://www.theatlantic.com/national/archive/2013/04/12-million-americans-believe-lizard-people-run-our-country/ 316706/
  26. 26. Reptilian • Altered our DNA so we don't fully use our brain • Control humans with media / politics • Have, through the generations, ruled the world
  27. 27. Using Android Things to Detect & Exterminate Reptilians
  28. 28. Detect
  29. 29. TensorFlow (09) (09) http://nilhcem.com/android/custom-tensorflow-classifier
  30. 30. TensorFlow codelabs • TensorFlow for Poets (10) • TensorFlow for Poets 2: Optimize for Mobile (11) • Android Things Image Classifier (12) (12) https://codelabs.developers.google.com/codelabs/androidthings-classifier/index.html (11) https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2/ (10) https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/
  31. 31. Inception v3 • Deep learning model for image recognition • Transfer learning
  32. 32. Gather lots of images
  33. 33. Transfer learning python tensorflow/examples/image_retraining/retrain.py --bottleneck_dir=~/tf_files/bottlenecks --how_many_training_steps 4000 --model_dir=~/tf_files/inception --output_graph=~/tf_files/retrained_graph.pb --output_labels=~/tf_files/retrained_labels.txt --image_dir ~/tf_files/reptilians
  34. 34. Generated files • retrained_graph.pb • retrained_labels.txt
  35. 35. Generated files $ cat retrained_labels.txt human reptile reptilian
  36. 36. Mobile model optimizations python tensorflow/python/tools/optimize_for_inference.py --input=~/tf_files/retrained_graph.pb --output=~/tf_files/optimized_graph.pb --input_names="Mul" --output_names="final_result"
  37. 37. TensorFlow Android Classify sample (13) (13) https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android
  38. 38. TensorFlow Inference val inferenceInterface = TensorFlowInferenceInterface(getAssets(), MODEL_FILE) val labels = loadLabels() // [ "reptilian", "reptile", "human" ] fun doRecognize(image: Bitmap) { val pixels = image.toPixelsArray() inferenceInterface.feed(INPUT_NODE, pixels, NETWORK_STRUCTURE) inferenceInterface.run(arrayOf(OUTPUT_NODE)) val outputs = FloatArray(labels.size) inferenceInterface.fetch(OUTPUT_NODE, outputs) }
  39. 39. TensorFlow Inference labels = [ "reptilian", "reptile", "human" ] outputs = [ 0.0098f , 0.0039f , 0.9863f ]
  40. 40. Test data
  41. 41. AndroidManifest.xml <application> <uses-library android:name="com.google.android.things" /> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.IOT_LAUNCHER" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application>
  42. 42. MainActivity class MainActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } }
  43. 43. "Hi! I use RelativeLayouts, lol"
  44. 44. <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:src="@drawable/background" android:layout_width="match_parent" android:layout_height="match_parent" /> <ImageView android:src="@drawable/reptilian" android:layout_width="280dp" android:layout_height="224dp" android:layout_gravity="bottom|center_horizontal" /> </FrameLayout>
  45. 45. "Layouts are dusty"
  46. 46. build.gradle dependencies { compileOnly 'com.google.android.things:androidthings:0.5.1-devpreview' }
  47. 47. Peripheral I/O APIs
  48. 48. Arduino Starter Kit
  49. 49. Peripheral I/O APIs (14) • GPIO • PWM • I²C • I²S • SPI • UART (14) https://developer.android.com/things/sdk/pio/index.html
  50. 50. Blinking LEDs
  51. 51. val pioService = PeripheralManagerService() val ledGpio = pioService.openGpio("BCM4")
  52. 52. Magic happens here ledGpio.value = true Thread.sleep(1000) ledGpio.value = false
  53. 53. LEDs (15) (15) https://fullmoonwanderer.deviantart.com/art/Reptilian-LED-resin-eyes-552330846
  54. 54. PeripheralManagerService fun openGpio(…): Gpio fun openPwm(…): Pwm fun openSpiDevice(…): SpiDevice fun openUartDevice(…): UartDevice fun openI2cDevice(…): I2cDevice fun openI2sDevice(…): I2sDevice
  55. 55. fun writeBuffer(device: I2cDevice, data: ByteArray) { device.write(data, data.size) }
  56. 56. Drivers are standard Android libraries (16) (17) (17) https://github.com/amitshekhariitbhu/awesome-android-things (16) https://github.com/androidthings/contrib-drivers
  57. 57. build.gradle compile 'com.google.android.things.contrib:driver-ssd1306:0.4'
  58. 58. MainActivity.kt val display = Ssd1306("I2C1") display.setPixel(x = 0, y = 0, on = true)
  59. 59. val display = Ssd1306("I2C1") val bmp = BitmapFactory.decodeResource(resources, R.drawable.background) BitmapHelper.setBmpData(display, 0, 0, bmp, false) display.show()
  60. 60. Android Things TensorFlow Sample (18) (18) https://github.com/androidthings/sample-tensorflow-imageclassifier
  61. 61. Camera
  62. 62. Cucumbers (?!?) (19) (19) https://cloud.google.com/blog/big-data/2016/08/how-a-japanese-cucumber-farmer-is-using-deep-learning-and- tensorflow
  63. 63. Detect when someone is approaching
  64. 64. Ultrasonic Sensor (HC-SR04)
  65. 65. Ultrasonic Sensor (HC-SR04) 1. Trigger 2. Echo
  66. 66. No Android Things compatible drivers
  67. 67. Arduino to the rescue
  68. 68. Arduino to the rescue
  69. 69. Arduino to the rescue void loop() { distance = getDistanceInCentimeters(); Serial.println(distance); delay(1000); }
  70. 70. Arduino to the rescue
  71. 71. Read data from USB (20) Hcsr04LiveData(this) .observe({lifecycle}) { distanceInCm -> Log.i(TAG, "Distance (cm): $distanceInCm") } (20) https://github.com/Nilhcem/usbfun-androidthings
  72. 72. HC-SR04 Hcsr04LiveData(this) .observe({lifecycle}) { distanceInCm -> if (distanceInCm < 25) { takePicture() } }
  73. 73. git commit -m "Kill reptilian when detected" if (detected.isReptilian()) { exterminate() }
  74. 74. Exterminate
  75. 75. Option #1: Gun
  76. 76. Servo motor
  77. 77. Servo motor
  78. 78. Servo motor
  79. 79. PWM servo compile 'com.google.android.things.contrib:driver-pwmservo:0.3'
  80. 80. Moving the servo val servo = Servo("PWM0") servo.setAngleRange(0.0, 180.0) servo.setPulseDurationRange(1.0, 2.0) servo.enable = true servo.angle = servo.minimumAngle
  81. 81. Moving the servo servo.angle = 42.0
  82. 82. Option #2: Flamethrower
  83. 83. Flamethrower (21) (21) https://www.youtube.com/watch?v=fh6oJZZ27Ro
  84. 84. Remote control • Nearby Connections API • Bluetooth LE • Embedded http server • Whatever you want
  85. 85. Option #3: Chainsaw
  86. 86. Relay module (22) (22) http://nilhcem.com/android-things/google-assistant-smart-home
  87. 87. Magic happens here relay.value = true
  88. 88. val colorAnimator = ValueAnimator.ofFloat(0f, 360f).apply { duration = 8000 repeatCount = ValueAnimator.INFINITE repeatMode = ValueAnimator.REVERSE addUpdateListener { animator -> val leds = getLedsColors(animator.animatedValue) ledstrip.write(leds) } start() }
  89. 89. val path = Path().apply { moveTo(0f, 0f) lineTo(0.001f, 400f / 2000f) // 0 secs -> 2.5 fps lineTo(3f / 23f, 400f / 2000f) // 3 secs -> 2.5 fps lineTo(6f / 23f, 20f / 2000f) // 6 secs -> 50.0 fps lineTo(18f / 23f, 20f / 2000f) // 18 secs -> 50.0 fps lineTo(1f, 1f) // 23 secs -> 0.5 fps } val frameDelayAnimator = ValueAnimator.ofInt(0, 2000).apply { duration = 23000 repeatCount = 0 interpolator = PathInterpolator(path) start() }
  90. 90. Using Android Things to Detect & Exterminate Reptilians
  91. 91. Conclusion
  92. 92. Android Things is Fun
  93. 93. Easy to get started
  94. 94. Reptilians suck (23) (23) Unless Reptilians are just an analogy to tell you not to blindly trust media and get you think about reality in a different way
  95. 95. Be a maker Try Android Things, really
  96. 96. Using Android Things to Detect & Exterminate Reptilians • Twitter: @Nilhcem • Slides: bit.ly/reptilethings

×