Skip to content

Instantly share code, notes, and snippets.

View seatedro's full-sized avatar

ro seatedro

  • Perplexity
  • nether realm
View GitHub Profile
@seatedro
seatedro / createTFRecord.py
Created October 4, 2020 13:48
Create TF Record
import pandas as pd
import numpy as np
import csv
import re
import cv2
import os
import glob
import xml.etree.ElementTree as ET
import io
@seatedro
seatedro / GetLatestCheckpoint.py
Created October 5, 2020 15:06
Clean-up checkpoints
output_directory = 'exported-models/'
# goes through the model is the training/ dir and gets the last one.
# you could choose a specfic one instead of the last
lst = os.listdir("models/my_mobilenet/")
# print(lst)
lst = [l for l in lst if 'ckpt-' in l and '.index' not in l]
steps=np.array([int(re.findall('\d+', l)[0]) for l in lst])
last_model = lst[steps.argmax()]
last_model_path = os.path.join('models/my_mobilenet', last_model)
@seatedro
seatedro / InferenceOnTFObjectDetection.py
Created October 5, 2020 15:19
InferenceOnTFObjectDetection
import numpy as np
from PIL import Image
from google.colab.patches import cv2_imshow
def load_image_into_numpy_array(path):
"""Load an image from file into a numpy array.
Puts image into numpy array to feed into tensorflow graph.
Note that by convention we put it into a numpy array with shape
(height, width, channels), where channels=3 for RGB.
@seatedro
seatedro / server.ts
Created August 26, 2022 13:51
Transcription Server 1
import express, { Express, Request, Response } from "express";
import { createServer } from "https";
const app: Express = express();
const server = createServer(
{
key: fs.readFileSync("key.pem"),
cert: fs.readFileSync("cert.pem"),
},
app
);
@seatedro
seatedro / server.ts
Last active August 26, 2022 13:57
Transcription Server 2
import { google } from "@google-cloud/speech/build/protos/protos";
import { Server, Socket } from "socket.io";
import speechToTextUtils from "./speechToTextUtils";
io.on("connection", (socket: Socket) => {
console.log("Socket Connection: ", socket.connected);
console.log("Socket Id: ", socket.id);
speechToTextUtils._socket = socket;
// Define socket eventListeners.
@seatedro
seatedro / speechToTextUtils.ts
Last active September 2, 2022 13:22
Transcription Server 1
import speech, { SpeechClient } from '@google-cloud/speech';
import { google } from '@google-cloud/speech/build/protos/protos';
import * as pumpify from 'pumpify';
import chalk from 'chalk';
import { Socket } from 'socket.io';
let speechClient: SpeechClient | null = null;
class SpeechToTextUtils {
recognizeStream!: pumpify | null;
resultEndTime = 0;
/**
* Receives streaming data and writes it to the recognizeStream for transcription
*
* @param {Buffer} data A section of audio data
*/
receiveData(data: DataView) {
if (
this.newStream &&
this.lastAudioInput.length !== 0 &&
this.recognizeStream
restartStream() {
if (this.recognizeStream) {
this.recognizeStream.end();
this.recognizeStream.removeAllListeners();
this.recognizeStream = null;
}
if (this.resultEndTime > 0) {
this.finalRequestEndTime = this.isFinalEndTime;
}
this.resultEndTime = 0;
import { io, Socket } from 'socket.io-client';
import {AudioStreamer} from 'src/app/app.service';
constructor(private audioStreamer: AudioStreamer) {
this.liveTranscription = '';
this.socket = io('https://localhost:3000');
this.socket.on('connect', () => {
console.log('Socket Connection: ', this.socket?.connected);
})
this.audioStreamer._socket = this.socket;
import { Injectable } from '@angular/core';
import { Socket } from 'socket.io-client';
// Stream Audio
let bufferSize = 2048,
AudioContext;
//audioStream constraints
const constraints = {
audio: true,