✨ add anime pictures and real pictures to be intelligently classified
This commit is contained in:
BIN
public/tfjs/anime_classifier/group1-shard10of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard10of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard11of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard11of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard12of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard12of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard13of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard13of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard14of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard14of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard15of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard15of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard16of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard16of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard17of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard17of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard18of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard18of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard19of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard19of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard1of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard1of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard20of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard20of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard21of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard21of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard2of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard2of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard3of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard3of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard4of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard4of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard5of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard5of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard6of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard6of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard7of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard7of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard8of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard8of21.bin
Normal file
Binary file not shown.
BIN
public/tfjs/anime_classifier/group1-shard9of21.bin
Normal file
BIN
public/tfjs/anime_classifier/group1-shard9of21.bin
Normal file
Binary file not shown.
1
public/tfjs/anime_classifier/model.json
Normal file
1
public/tfjs/anime_classifier/model.json
Normal file
File diff suppressed because one or more lines are too long
@@ -4,7 +4,8 @@ import i18n from "@/locales";
|
||||
import {NSFWJS} from "nsfwjs";
|
||||
import {message} from "ant-design-vue";
|
||||
|
||||
import {loadCocoSsd, loadMobileNet} from "@/utils/tfjs";
|
||||
// import {loadCocoSsd, loadMobileNet} from "@/utils/tfjs/tfjs.ts";
|
||||
import {loadModel, predictImage} from "@/utils/tfjs/anime_classifier.ts";
|
||||
|
||||
export const useUploadStore = defineStore(
|
||||
'upload',
|
||||
@@ -25,11 +26,19 @@ export const useUploadStore = defineStore(
|
||||
message.error(i18n.global.t('comment.illegalImage'));
|
||||
return false;
|
||||
}
|
||||
const predictions = await loadMobileNet(image);
|
||||
console.log(predictions);
|
||||
// const predictions = await loadMobileNet(image);
|
||||
// console.log(predictions);
|
||||
//
|
||||
// const prediction = await loadCocoSsd(image);
|
||||
// console.log(prediction);
|
||||
|
||||
const prediction = await loadCocoSsd(image);
|
||||
console.log(prediction);
|
||||
const model = await loadModel('/tfjs/anime_classifier/model.json');
|
||||
|
||||
// 进行预测
|
||||
const output = await predictImage(model, image);
|
||||
console.log(output);
|
||||
|
||||
// console.log('Predicted Class:', predictedClass);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
23
src/utils/tfjs/anime_classifier.ts
Normal file
23
src/utils/tfjs/anime_classifier.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import * as tf from '@tensorflow/tfjs';
|
||||
|
||||
// 封装处理图像和推理的工具函数
|
||||
export async function loadModel(modelPath) {
|
||||
const model = await tf.loadGraphModel(modelPath);
|
||||
console.log('Model Loaded');
|
||||
return model;
|
||||
}
|
||||
|
||||
// 处理图片并进行推理
|
||||
export async function predictImage(model, imageElement) {
|
||||
// 将图片转换为张量
|
||||
const tensor = tf.browser.fromPixels(imageElement).toFloat();
|
||||
const resized = tf.image.resizeBilinear(tensor, [224, 224]); // 调整图片大小为模型输入大小
|
||||
const input = resized.expandDims(0); // 增加批次维度
|
||||
|
||||
// 进行推理
|
||||
const prediction = model.predict(input);
|
||||
|
||||
// 获取预测结果并返回
|
||||
const resultArray = await prediction.array();
|
||||
return resultArray[0]; // 返回第一项的预测结果
|
||||
}
|
Reference in New Issue
Block a user