Skip to content

Instantly share code, notes, and snippets.

@FreeFly19
FreeFly19 / data_loading_cell.py
Last active November 21, 2022 20:22
Tensorflow 2.0 Dataloading with aug and caching
import tensorflow as tf
train_ds = tf.keras.utils.image_dataset_from_directory(
train_dir,
validation_split=0.1,
subset="training",
label_mode="categorical",
#shuffle=True,
seed=123,
image_size=(image_size, image_size),
@FreeFly19
FreeFly19 / f1_definition.py
Created November 18, 2022 15:34
F1 metric for keras
import keras.backend as K
def f1(y_true, y_pred):
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
precision = true_positives / (predicted_positives + K.epsilon())
recall = true_positives / (possible_positives + K.epsilon())
f1_val = 2*(precision*recall)/(precision+recall+K.epsilon())
return f1_val
@FreeFly19
FreeFly19 / ArrayListExample.java
Created July 24, 2022 19:30
ArrayList, LinkedList
public class ArrayListExample {
public static void main(String[] args) {
MyArrayList<Long> listOfInts = new MyArrayList<>();
listOfInts.push(20L);
listOfInts.push(23L);
listOfInts.push(22L);
listOfInts.push(24L);
listOfInts.remove(23L);
@FreeFly19
FreeFly19 / client.py
Created February 15, 2022 17:51
Python TCP server and client
import socket
import sys
import threading
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.connect(('127.0.0.1', 9999))
def read_from_socket(socket):
while True:
message = socket.recv(2048)
@FreeFly19
FreeFly19 / es.ts
Last active January 14, 2022 15:39
interface Template {
id: string;
name: string;
}
interface Document {
}
interface State {
templates: Template[];
#define IR_SEND_PIN 27
#include <IRremote.h>
int RECV_PIN = 14;
IRrecv irrecv(RECV_PIN);
IRsend irsend;
int lastAddress = 1;
int lastCommand = 1;
@FreeFly19
FreeFly19 / IRReader.c
Created August 9, 2021 21:19
EuroLamp IR codes reader
#include <IRremote.h>
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
void setup() {
Serial.begin(9600);
irrecv.enableIRIn();
}
@FreeFly19
FreeFly19 / CoreApplication.java
Created July 16, 2021 08:26
DJI Image metadata parser
package ai.spector;
import com.adobe.xmp.XMPIterator;
import com.adobe.xmp.XMPMeta;
import com.adobe.xmp.properties.XMPPropertyInfo;
import com.drew.imaging.ImageMetadataReader;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import com.drew.metadata.xmp.XmpDirectory;
import lombok.Data;
import java.util.*;
public class MainIndex {
public static void main(String[] args) {
Map<String, Set<Post>> postFullText = new HashMap<>();
Post p1 = new Post();
p1.id = 1L;