Skip to content

Instantly share code, notes, and snippets.

Avatar

krissanawat101 krissnawat

View GitHub Profile
View gist:80857f23af77267115ab7ce1ffc28866
eventEmitter.on('currentModeChanged', newMode => {
if (newMode == 'dark') {
setTheme(true);
} else {
setTheme(false);
}
});
View index.js
const Home = () => {
return (
<View>
<Headline style={{ marginLeft: 23 }}>Lastest Post</Headline>
<Card
style={{
shadowOffset: { width: 5, height: 5 },
width: '90%',
borderRadius: 12,
alignSelf: 'center',
View index.js
let express = require("express");
let app = express();
let port = 8080;
app.use(express.static("./src"));
app.listen(port, function () {
console.log(`Listening at http://localhost:${port}`);
});
View predict.js
$("#predictBtn").click(async function () {
let image = $('#selected-image').get(0);
let pre_image = tf.browser.fromPixels(image, 3)
.resizeNearestNeighbor([224, 224])
.expandDims()
.toFloat()
.reverse(-1);
let predict_result = await model.predict(pre_image).data();
View predict.js
$("#predictBtn").click(async function () {
let image = $('#selected-image').get(0);
console.log("Loading image...");
let tensor = tf.browser.fromPixels(image, 3)
.resizeNearestNeighbor([224, 224])
.expandDims()
.toFloat()
View predict.js
let model;
$(document).ready(async function () {
$('.progress-bar').show();
model = await tf.loadGraphModel('model/model.json');
$('.progress-bar').hide();
});
View predict.js
const Result = {
0: "Fresh",
1: "Rotten"
};
$("#image-selector").change(function () {
let reader = new FileReader();
reader.onload = function () {
let dataURL = reader.result;
$("#selected-image").attr("src", dataURL);
$("#prediction-list").empty();
View index.html
<script src="https://code.jquery.com/jquery-3.5.1.slim.js"
integrity="sha256-DrT5NfxfbHvMHux34647547Y6of8TaYyK50jnxRnM=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"
integrity="sha384-OgVRvuATP4563545U7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js"></script>
<script src="predict.js"></script>
</body>
View index.html
<body>
<main role="main" class="container mt-5">
<div class="row">
<div class="col-12">
<div class="progress progress-bar progress-bar-striped progress-bar-animated mb-2">
Loading Model
</div>
</div>
</div>
<div class="row">
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Fresh or Rotten</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Detect Rotten or Fresh Orange in Browser" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
You can’t perform that action at this time.