This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
checkpoint = torch.load("pathtosavemodel") | |
model = SimpleNet(num_classes=10) | |
model.load_state_dict(checkpoint) | |
model.eval() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from torchvision.datasets import CIFAR10 | |
from torchvision.transforms import transforms | |
from torch.utils.data import DataLoader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import torch.nn as nn | |
from torch.autograd import Variable | |
import keras.backend as K | |
from keras.models import * | |
from keras.layers import * | |
import torch | |
from torchvision.models import squeezenet1_1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.models import Model | |
from keras.layers import * | |
import os | |
import tensorflow as tf | |
def keras_to_tensorflow(keras_model, output_dir, model_name,out_prefix="output_", log_tensorboard=True): | |
if os.path.exists(output_dir) == False: | |
os.mkdir(output_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.specpal.mobileai; | |
import android.content.res.AssetManager; | |
import android.graphics.Bitmap; | |
import android.graphics.Canvas; | |
import android.graphics.Matrix; | |
import android.os.Environment; | |
import java.io.File; | |
import java.io.FileOutputStream; | |
import java.io.InputStream; | |
import org.json.*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Load the tensorflow inference library | |
static { | |
System.loadLibrary("tensorflow_inference"); | |
} | |
//PATH TO OUR MODEL FILE AND NAMES OF THE INPUT AND OUTPUT NODES | |
private String MODEL_PATH = "file:///android_asset/squeezenet.pb"; | |
private String INPUT_NAME = "input_1"; | |
private String OUTPUT_NAME = "output_1"; | |
private TensorFlowInferenceInterface tf; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//FUNCTION TO COMPUTE THE MAXIMUM PREDICTION AND ITS CONFIDENCE | |
public Object[] argmax(float[] array){ | |
int best = -1; | |
float best_confidence = 0.0f; | |
for(int i = 0;i < array.length;i++){ | |
float value = array[i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void predict(final Bitmap bitmap){ | |
//Runs inference in background thread | |
new AsyncTask<Integer,Integer,Integer>(){ | |
@Override | |
protected Integer doInBackground(Integer ...params){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
setSupportActionBar(toolbar); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from imageai.Detection import ObjectDetection | |
import os | |
execution_path = os.getcwd() | |
detector = ObjectDetection() | |
detector.setModelTypeAsYOLOv3() | |
detector.setModelPath( os.path.join(execution_path , "yolo.h5")) | |
detector.loadModel() | |
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "image.jpg"), output_image_path=os.path.join(execution_path , "imagenew.jpg"), minimum_percentage_probability=30) |