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 tensorflow as tf | |
from tensorflow import keras | |
from keras import layers | |
conv_base = keras.applications.mobilenet_v2.MobileNetV2( | |
weights="imagenet", | |
include_top=False | |
) | |
conv_base.trainable = False |
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
conv_base = keras.applications.vgg16.VGG16( | |
weights="imagenet", | |
include_top=False | |
) | |
conv_base.trainable = False | |
inputs = keras.Input(shape=(256, 256, 3)) | |
x = data_augmentation(inputs) | |
x = keras.applications.vgg16.preprocess_input(x) | |
x = conv_base(x) |
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
name: tflite_image_classification | |
description: A new Flutter project. | |
publish_to: 'none' # Remove this line if you wish to publish to pub.dev | |
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html | |
version: 1.0.0+1 | |
environment: | |
sdk: ">=2.16.1 <3.0.0" |
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 'package:flutter/material.dart'; | |
import 'package:tflite_image_classification/tflite_model.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); |
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 'dart:io'; | |
import 'package:flutter/material.dart'; | |
import 'package:image_picker/image_picker.dart'; | |
import 'package:tflite/tflite.dart'; | |
class TfliteModel extends StatefulWidget { | |
const TfliteModel({Key? key}) : super(key: key); | |
@override |
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 tensorflow import keras | |
import pathlib | |
test_model = keras.models.load_model(f"{hotDogDir}hotdog_classifier_v4.keras") | |
converter = tensorflow.lite.TFLiteConverter.from_keras_model(test_model) | |
tflite_model = converter.convert() | |
tflite_models_dir = pathlib.Path(f"{hotDogDir}") | |
tflite_models_dir.mkdir(exist_ok=True, parents=True) |
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 PIL import Image | |
import tensorflow as tf | |
from tensorflow import keras | |
from keras import layers | |
import os | |
import matplotlib.pyplot as plt | |
import numpy as np | |
def download_and_predict(url, filename): | |
test_model = keras.models.load_model(f"{hotDogDir}hotdog_classifier_v4.keras") |
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
conv_base = keras.applications.vgg16.VGG16( | |
weights="imagenet", | |
include_top=False | |
) | |
conv_base.trainable = False | |
inputs = keras.Input(shape=(256, 256, 3)) | |
x = data_augmentation(inputs) | |
x = keras.applications.vgg16.preprocess_input(x) | |
x = conv_base(x) |
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
inputs = keras.Input(shape=(8, 8, 512)) | |
x = layers.Flatten()(inputs) | |
x = layers.Dense(256)(x) | |
x = layers.Dropout(0.5)(x) | |
outputs = layers.Dense(1, activation= keras.activations.sigmoid)(x) | |
model = keras.Model(inputs, outputs) | |
model.compile(optimizer=keras.optimizers.RMSprop(), | |
loss=keras.losses.BinaryCrossentropy(), | |
metrics=["accuracy"]) |
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 numpy as np | |
def get_features_and_labels(dataset): | |
all_features = [] | |
all_labels = [] | |
for images, labels in dataset: | |
preprocessed_images = keras.applications.vgg16.preprocess_input(images) | |
features = conv_base.predict(preprocessed_images) | |
all_features.append(features) | |
all_labels.append(labels) |
NewerOlder