This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
keep_p = 1- dropout_p | |
a = np.sqrt(target_var / (keep_p *((1-keep_p) * np.power(alpha-target_mean,2) + target_var))) | |
b = target_mear - a * (keep_p * target_mean + (1 - keep_p) * alpha) | |
def alpha_dropout(x, alpha_p=-1.758, dropout_p=0.05): | |
mask = np.random.rand(*x.shape) > dropout_p | |
x[mask] = alpha_p | |
output = a*x + b | |
return output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def selu(x): | |
alpha = 1.6732632423543772848170429916717 | |
lambdaa = 1.0507009873554804934193349852946 | |
return lambdaa*np.where(x>=0.0, x, alpha*np.exp(x)-alpha) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
from flask import Flask, render_template | |
app = Flask(__name__) | |
# keep runnign process global | |
proc = None | |
@app.route("/") | |
def hello(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<!-- Be Mobile Friendly --> | |
<meta name="viewport" content="width=device-width,height=device-height initial-scale=1"> | |
<title>TalkingRaspi</title> | |
<meta name="description" content="Talkingraspi interface"> | |
<meta name="author" content="Eren Golge"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import smtplib | |
import uuid | |
import os | |
import glob | |
from os.path import basename | |
from email.mime.application import MIMEApplication | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################### | |
# LOGIC | |
################################################################################### | |
# check to see if the room is occupied | |
if text == "Occupied": | |
# save occupied frame | |
cv2.imwrite("/tmp/talkingraspi_{}.jpg".format(motionCounter), frame); | |
# check to see if enough time has passed between uploads |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# thresholding difference frame for filling holes and noise reduction | |
# finding contours of moving regions | |
thresh = cv2.threshold(frameDelta, conf["delta_thresh"], 255, | |
cv2.THRESH_BINARY)[1] | |
thresh = cv2.dilate(thresh, None, iterations=2) | |
im2 ,cnts, _ = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, | |
cv2.CHAIN_APPROX_SIMPLE) | |
# loop over the contours | |
for c in cnts: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# capture frames from the camera | |
for f in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True): | |
# grab the raw NumPy array representing the image and initialize | |
# the timestamp and occupied/unoccupied text | |
frame = f.array | |
timestamp = datetime.datetime.now() | |
text = "Unoccupied" | |
###################################################################### | |
# COMPUTER VISION |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# allow the camera to warmup, then initialize the average frame, last | |
# uploaded timestamp, and frame motion counter | |
print "[INFO] warming up..." | |
time.sleep(conf["camera_warmup_time"]) | |
avg = None | |
lastUploaded = datetime.datetime.now() | |
motionCounter = 0 | |
print('[INFO] talking raspi started !!') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from picamera.array import PiRGBArray | |
from picamera import PiCamera | |
from utils import send_email, TempImage | |
import argparse | |
import warnings | |
import datetime | |
import json | |
import time | |
import cv2 |