我按照https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html的示例在一些图像上训练了 CNN 模型。我的模型代码是相同的,我只是在另一个图像数据集上训练它:也用于两个类之间的分类。
结果是您对训练集的期望:图像被正确分类为 0 或 1。
我在tensorflowjs友好的格式保存的模型下面的“替代方案:使用Python API出口直接TF.js层格式”的部分 https://js.tensorflow.org/tutorials/import-keras.html
但是,当我尝试使用 javascript 访问 html 页面中的结果时,几乎每个图像(或接近它)都会得到 1:即使图像在 Keras 中给出 0。
我什至在 JSON 中将图像保存为张量,在 Keras 中得到 0,在 TensorflowJS 中得到 1。这是一个错误还是我在某个地方犯了错误?
这是我在 TensorflowJS 中访问 json 的代码:
<html>
<head>
<!-- Load TensorFlow.js -->
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.13.0"></script>
<script>
// /sf/answers/1282706911/
function callAjax(url, callback){
var xmlhttp;
// compatible with IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
callback(xmlhttp.responseText); …Run Code Online (Sandbox Code Playgroud)