Advertisement

Using Android Things to Detect & Exterminate Reptilians

Nilhcem
Jul. 14, 2017
Advertisement

More Related Content

Similar to Using Android Things to Detect & Exterminate Reptilians(20)

Advertisement

Using Android Things to Detect & Exterminate Reptilians

  1. Using Android Things to Detect & Exterminate Reptilians
  2. Android is EVERYWHERE (01) (01) Reptilians too are everywhere, but they suck.
  3. Android Things
  4. "If you can build an app, you can build a device!"
  5. 8-bit Distributed Piano (02) (02) https://riggaroo.co.za/android-things-building-distributed-piano/
  6. Play Music Like a Scientist
  7. Beer Can Music Player (03) (03) http://nilhcem.com/android-things/discovering-the-I2C-api-creating-a-capacitive-sensor-driver
  8. Notification Cat (04) (04) http://nilhcem.com/android-things/bluetooth-low-energy
  9. Google Assistant powered Robot (05) (05) http://nilhcem.com/android-things/create-your-google-assistant-robots
  10. OK, BUT, WHY? I mean... I can use an Arduino too
  11. Perfect for • Doing some computation locally • Using Google Services • A secure platform • Prototype and production
  12. Perfect for • Doing some computation locally • Using Google Services • A secure platform • Prototype and production
  13. Perfect for • Doing some computation locally • Using Google Services • A secure platform • Prototype and production
  14. Perfect for • Doing some computation locally • Using Google Services • A secure platform • Prototype and production
  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. Raspberry Pi 3 - NXP i.MX7D
  17. SOM (System on module)
  18. SOM (System on module)
  19. Edison Candle (07) (07) https://github.com/androidthings/edison-candle
  20. SOMs are pre-certified for regulator approvals
  21. Perfect for • Doing some computation locally • Using Google Services • A secure platform • Prototype and production
  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. Reason?
  24. REPTILIANS
  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. 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. Using Android Things to Detect & Exterminate Reptilians
  28. Detect
  29. TensorFlow (09) (09) http://nilhcem.com/android/custom-tensorflow-classifier
  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. Inception v3 • Deep learning model for image recognition • Transfer learning
  32. Gather lots of images
  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. Generated files • retrained_graph.pb • retrained_labels.txt
  35. Generated files $ cat retrained_labels.txt human reptile reptilian
  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. TensorFlow Android Classify sample (13) (13) https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android
  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. TensorFlow Inference labels = [ "reptilian", "reptile", "human" ] outputs = [ 0.0098f , 0.0039f , 0.9863f ]
  40. Test data
  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. MainActivity class MainActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } }
  43. "Hi! I use RelativeLayouts, lol"
  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. "Layouts are dusty"
  46. build.gradle dependencies { compileOnly 'com.google.android.things:androidthings:0.5.1-devpreview' }
  47. Peripheral I/O APIs
  48. Arduino Starter Kit
  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. Blinking LEDs
  51. val pioService = PeripheralManagerService() val ledGpio = pioService.openGpio("BCM4")
  52. Magic happens here ledGpio.value = true Thread.sleep(1000) ledGpio.value = false
  53. LEDs (15) (15) https://fullmoonwanderer.deviantart.com/art/Reptilian-LED-resin-eyes-552330846
  54. PeripheralManagerService fun openGpio(…): Gpio fun openPwm(…): Pwm fun openSpiDevice(…): SpiDevice fun openUartDevice(…): UartDevice fun openI2cDevice(…): I2cDevice fun openI2sDevice(…): I2sDevice
  55. fun writeBuffer(device: I2cDevice, data: ByteArray) { device.write(data, data.size) }
  56. Drivers are standard Android libraries (16) (17) (17) https://github.com/amitshekhariitbhu/awesome-android-things (16) https://github.com/androidthings/contrib-drivers
  57. build.gradle compile 'com.google.android.things.contrib:driver-ssd1306:0.4'
  58. MainActivity.kt val display = Ssd1306("I2C1") display.setPixel(x = 0, y = 0, on = true)
  59. val display = Ssd1306("I2C1") val bmp = BitmapFactory.decodeResource(resources, R.drawable.background) BitmapHelper.setBmpData(display, 0, 0, bmp, false) display.show()
  60. Android Things TensorFlow Sample (18) (18) https://github.com/androidthings/sample-tensorflow-imageclassifier
  61. Camera
  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. Detect when someone is approaching
  64. Ultrasonic Sensor (HC-SR04)
  65. Ultrasonic Sensor (HC-SR04) 1. Trigger 2. Echo
  66. No Android Things compatible drivers
  67. Arduino to the rescue
  68. Arduino to the rescue
  69. Arduino to the rescue void loop() { distance = getDistanceInCentimeters(); Serial.println(distance); delay(1000); }
  70. Arduino to the rescue
  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. HC-SR04 Hcsr04LiveData(this) .observe({lifecycle}) { distanceInCm -> if (distanceInCm < 25) { takePicture() } }
  73. git commit -m "Kill reptilian when detected" if (detected.isReptilian()) { exterminate() }
  74. Exterminate
  75. Option #1: Gun
  76. Servo motor
  77. Servo motor
  78. Servo motor
  79. PWM servo compile 'com.google.android.things.contrib:driver-pwmservo:0.3'
  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. Moving the servo servo.angle = 42.0
  82. Option #2: Flamethrower
  83. Flamethrower (21) (21) https://www.youtube.com/watch?v=fh6oJZZ27Ro
  84. Remote control • Nearby Connections API • Bluetooth LE • Embedded http server • Whatever you want
  85. Option #3: Chainsaw
  86. Relay module (22) (22) http://nilhcem.com/android-things/google-assistant-smart-home
  87. Magic happens here relay.value = true
  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. 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. Using Android Things to Detect & Exterminate Reptilians
  91. Conclusion
  92. Android Things is Fun
  93. Easy to get started
  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. Be a maker Try Android Things, really
  96. Using Android Things to Detect & Exterminate Reptilians • Twitter: @Nilhcem • Slides: bit.ly/reptilethings
Advertisement