Skip to content

Instantly share code, notes, and snippets.

View solix's full-sized avatar

Soheil solix

View GitHub Profile
@solix
solix / mqtt-android.java
Created January 4, 2018 10:21
snippet for mqtt android
BroadcastReceiver mqtt_reciever = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String data = intent.getStringExtra("msg-sub");
Log.d("MQTT", "Temperature"+ data);
}
};
//launch
#from models/object_detection
python3 train.py --logstderr --train_dir=training/ --pipeline_config_path=data/ssd_mobilenet_v1_coco.config
@solix
solix / delete git file from history
Last active August 8, 2017 13:24
git delete file from history
git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch app/src/main/assets/yolo.pb' HEAD
OR
git filter-branch -f \ [15:23:39]
--index-filter 'git rm --cached --ignore-unmatch app/src/main/assets/output_graph_opt.pb' HEAD
# training_gen = generator_batch(X_train)
# val_gen = generator_batch(X_validation)
datagen = ImageDataGenerator(
featurewise_center=True,
featurewise_std_normalization=True,
rotation_range=20,
width_shift_range=0.2,
height_shift_range=0.2,
horizontal_flip=True)
@solix
solix / imageDataGenerator.py
Created April 26, 2017 23:00
Keras augment data image
datagen = ImageDataGenerator(
featurewise_center=True, # set input mean to 0 over the dataset
samplewise_center=False, # set each sample mean to 0
featurewise_std_normalization=True, # divide inputs by std of the dataset
samplewise_std_normalization=False, # divide each input by its std
zca_whitening=False, # apply ZCA whitening
rotation_range=20, # randomly rotate images in the range (degrees, 0 to 180)
width_shift_range=0.2, # randomly shift images horizontally (fraction of total width)
height_shift_range=0.2, # randomly shift images vertically (fraction of total height)
horizontal_flip=True, # randomly flip images
@solix
solix / pickle.py
Last active April 5, 2017 18:49
save and load pickle
# Save
dist_pickle = {}
dist_pickle["mtx"] = mtx
dist_pickle["dist"] = dist
pickle.dump( dist_pickle, open( filename, "wb" ) )
#load
#1.1 load pickle
calib_dist = pickle.load(open(filename,"rb"))
def generator(features=X_train, labels=y_train, batch_size=FLAGS.batch_size):
# Create empty arrays to contain batch of features and labels#
batch_features = np.zeros((batch_size,160,320,3))
print("batch_feature shape is {}".format(batch_features.shape))
batch_labels = np.zeros((batch_size,1))
while True:
for i in range(batch_size):
#choose random index in features
index= random.choice(len(features),1)
batch_features[i] = features[index]
@solix
solix / readcsv.py
Last active March 14, 2017 16:23
import csv and read value pandas
import pandas as pd
# type of reader is dataframe
reader = pd.read_csv('./data/example.csv', usecols=['c1','c2','c5','c10'] ) #choose csv file labels
#iterate through dataframe and get specific values
for index, row in reader.iterrows():
print(row['c1'], row['c10'])
@solix
solix / Flags_snippet.py
Last active March 12, 2017 11:38
Flag file
# Here's how you would run the file
# from the command line: python feature_extraction.py --training_file vgg_cifar10_100_bottleneck_features_train.p
# --validation_file vgg_cifar10_bottleneck_features_validation.p
flags = tf.app.flags
FLAGS = flags.FLAGS
# command line flags
flags.DEFINE_string('training_file', '', "Bottleneck features training file (.p)")
flags.DEFINE_string('validation_file', '', "Bottleneck features validation file (.p)")
@solix
solix / loadCifar10Data.py
Created March 12, 2017 10:24
Keras import dataset and reshape
from keras.datasets import cifar10
(X_train, y_train), (X_test, y_test) = cifar10.load_data()
# y_train.shape is 2d, (50000, 1). While Keras is smart enough to handle this
# it's a good idea to flatten the array.
y_train = y_train.reshape(-1)
y_test = y_test.reshape(-1)
assert(len(X_train) == len(y_train))
assert(len(X_test) == len(y_test))