Skip to content

Instantly share code, notes, and snippets.

View crearo's full-sized avatar
🥨

Rish Bhardwaj crearo

🥨
View GitHub Profile
@rstml
rstml / crop.md
Last active June 9, 2023 06:02
Keras center and random crop support for ImageDataGenerator

Keras center and random crop support for ImageDataGenerator

preprocess_crop.py script below adds center and random crop to Keras's flow_from_directory data generator.

It first resizes image preserving aspect ratio and then performs crop. Resized image size is based on crop_fraction which is hardcoded but can be changed. See crop_fraction = 0.875 line where 0.875 appears to be the most common, e.g. 224px crop from 256px image.

Note that the implementation has been done by monkey patching keras_preprocessing.image.utils.loag_img function as I couldn't find any other way to perform crop before resizing without rewriting many other classes above.

Due to these limitations, the cropping method is enumerated into the interpolation field. Methods are delimited by : where the first part is interpolation and second is crop e.g. lanczos:random. Supported crop methods are none, center, random. When no crop method is specified, none is assumed.

from keras.models import Sequential
from keras.layers import Dense, Activation
dims = X_train.shape[1]
print(dims, 'dims')
print("Building model...")
nb_classes = Y_train.shape[1]
print(nb_classes, 'classes')
@mg6maciej
mg6maciej / MoshiExtensions.kt
Created May 6, 2017 10:07
Moshi generic type adapters
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import java.lang.reflect.Type
// val adapter = moshi.listAdapter<MyModel>()
// val adapter = moshi.mapAdapter<String, List<MyModel>>(valueType = listType<MyModel>())
inline fun <reified E> Moshi.listAdapter(elementType: Type = E::class.java): JsonAdapter<List<E>> {
return adapter(listType<E>(elementType))
@hauptmech
hauptmech / aruco_test.py
Created July 15, 2016 07:05
Quick test of aruco with python
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
#dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_5X5_1000)
dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_4X4_50)
#dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_ARUCO_ORIGINAL)
while(True):
# Capture frame-by-frame
@intrepid-ab
intrepid-ab / proguard-project.txt
Created June 8, 2016 18:27
Proguard Configuration for Android Library
# Save the obfuscation mapping to a file, so we can de-obfuscate any stack
# traces later on. Keep a fixed source file attribute and all line number
# tables to get line numbers in the stack traces.
# You can comment this out if you're not interested in stack traces.
-printmapping out.map
-keepparameternames
-renamesourcefileattribute SourceFile
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
SourceFile,LineNumberTable,EnclosingMethod
public class MemoryUtility
{
public static long getTotalInternalMemory( Context context )
{
long totalSpace = new File(context.getFilesDir().getAbsoluteFile().toString()).getTotalSpace();
return totalSpace;
}
@antonshkurenko
antonshkurenko / Dagger 2, quick start
Last active June 18, 2018 19:27
Everything I found about Dagger 2
Dagger step 1: Add android-apt, dagger 2, dagger2-compiler, and javax annotation to the build.gradle files.
Note that they're not all "compile" dependencies.
Step 2: Add our module. Our ApplicationModule will be able to inject the ApplicationContext to classes that need it.
Step 3: Add our Component.Dagger 2 generates code for each Component you create,
using the file name Dagger(NameOfComponent).
Example: DaggerApplicationComponent.
Components can have multiple modules, in our case we have one.
@wonchulee
wonchulee / gstreamer_cerbero_android.md
Last active March 30, 2019 06:03
how to build GStreamer cerbero for Android

How to build GStreamer cerbero for Android

###Clone and build cerbero

clone cerbero from gstreamer, not sdk/gstreamer

git clone git://anongit.freedesktop.org/gstreamer/cerbero

build cerbero for getting gstreamer-1.0-android-armv7-<version>.zip

@ericandrewlewis
ericandrewlewis / index.md
Last active June 6, 2024 01:43
C++ Pointer Tutorial

C++ Pointer Tutorial

Because pointers can be ugh

"Regular" variables (not pointers)

To understand a pointer, let's review "regular" variables first. If you're familiar with a programming language without pointers like JavaScript, this is what you think when you hear "variable".

When declaring a variable by identifier (or name), the variable is synonymous with its value.

@floe
floe / gst-appsrc.c
Last active April 3, 2023 12:11
example appsrc for gstreamer 1.0 with own mainloop & external buffers
// example appsrc for gstreamer 1.0 with own mainloop & external buffers. based on example from gstreamer docs.
// public domain, 2015 by Florian Echtler <floe@butterbrot.org>. compile with:
// gcc --std=c99 -Wall $(pkg-config --cflags gstreamer-1.0) -o gst-appsrc gst-appsrc.c $(pkg-config --libs gstreamer-1.0) -lgstapp-1.0
#include <gst/gst.h>
#include <gst/app/gstappsrc.h>
#include <stdint.h>
int want = 1;