Tuesday, March 26, 2019

Tensorflow Lite Demo

As part of my requirements, have started deploying tensorflow models on Android using Tensorflow Lite
Amazing experience



import tensorflow as tf
# Convert to TensorFlow Lite model.
converter = tf.lite.TFLiteConverter.from_keras_model_file('sunroof_model.h5')
tflite_model = converter.convert()
open("sunroof_model.tflite", "wb").write(tflite_model)

Below are few errors have experienced while developing android code

"Attempt to invoke virtual method 'void org.tensorflow.lite.Interpreter.run(java.lang.Object, java.lang.Object)' on a null object reference"
Cannot copy between a TensorFlowLite tensor with shape [1, 1] and a Java object with shape [1].
Cannot copy between a TensorFlowLite tensor with shape [1, 6] and a Java object with shape [6].

Friday, March 22, 2019

What are the contraints for tensorflow scope names?

While developing TF model, have faced the below issue



Solution: remove the spaces in the feature names

The kernel appears to have died. It will restart automatically

Got strange issue on my new setup
No module named 'numpy.core._multiarray_umath'

Solution: Just upgrade numpy

Thursday, February 28, 2019

Success formula in our life

  1. Insatiable appetite for knowledge
  2. Know the basics 
  3. Identify the gaps in your knowledge 
  4. Constantly update 
  5. Expose the linkages 
  6. Expose diverse views 
  7. Write, argue and debate
Reference: https://www.youtube.com/watch?v=_svETMOY9zY

Monday, February 4, 2019

Hyper parameters with GridSearch

Building a better model involves iteration and tuning these hyperparameters.
Grid search uses cross validation, splitting the training data up into folds for training and testing of each hyperparameter combination. After all hyperparameter variants are trained, the original test data is used to validate the final model.
GridSearchCV takes a dictionary that describes the parameters that should be tried and a model to train. The grid of parameters is defined as a dictionary, where the keys are the parameters and the values are the settings to be tested.
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import classification_report
from keras.wrappers.scikit_learn import KerasClassifier
from keras.models import Sequential
import time

def dense_model(units, dropout):
    model = Sequential()
    model.add(Dense(units, activation='relu', input_shape=(28, 28,)))
    model.add(Dropout(dropout))
    model.add(Dense(units, activation='relu'))
    model.add(Dropout(dropout))
    model.add(Flatten())
    model.add(Dense(10, activation='softmax'))
    model.compile(loss='categorical_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])
    return model

hyperparameters = {
    'epochs': [1],
    'batch_size': [64],
    'units': [32, 64, 128],
    'dropout': [0.1, 0.2, 0.4]
}

model = KerasClassifier(build_fn=dense_model, verbose=0)
start = time.clock()
grid = GridSearchCV(estimator=model, param_grid=hyperparameters, cv=6, verbose=4)
grid_result = grid.fit(x_train, y_train)
print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_))

y_true, y_pred = np.argmax(y_test, axis=1), grid.predict(x_test)
print()
print(classification_report(y_true, y_pred))
print()
print(time.clock() - start)

Wednesday, January 16, 2019

Another Computer Vision application on AWS

URL: http://iamsam.tech/















Technical areas: S3 Bucket, Amazon ML+ Rekognition, boto3 python package