2020年8月16日

scratch3_knn安裝記錄

 github:https://github.com/CodeLabClub/scratch3_knn

參考文章:https://github.com/CodeLabClub/scratch3_knn_install

cd   scratch-gui/node_modules/scratch-vm/src/exteions

git clone https://github.com/CodeLabClub/scratch3_knn.git

cd scratch3_knn

cp -r knn ../../../../../static

vim mobilenet.js

約1083行

註解//var BASE_PATH = 'http://storage.codelab.club/tfjs-models/tfjs/'

 改成var BASE_PATH = '../static/knn/';

vim index.js

把這三行註解

//import * as tf from '@tensorflow/tfjs';
//import * as mobilenetModule from './mobilenet.js';
//import * as knnClassifier from '@tensorflow-models/knn-classifier';
 加入

const tf = require('@tensorflow/tfjs');
const mobilenetModule = require('./mobilenet.js');
const knnClassifier = require('@tensorflow-models/knn-classifier'); 


 vim ../../extension-support/extension-manager.js

 在const builtinExtensions = {
中的最後面加上,,按下enter,再貼上cxknn:() =>require('../extensions/scratch3_knn')


 

 cd ../../../../../src/lib/libraries/extensions/

mkdir knnAlgorithm

加入圖片knnAlgorithm.png 和 knnAlgorithm-small.svg

 vim index.jsx

在import的最後面加入二行

import knnalgorithmImage from './knnAlgorithm/knnAlgorithm.png';
import knnalgorithmInsetImage from './knnAlgorithm/knnAlgorithm-small.svg';

 在export default [的最後面加入

{
       name: (
           <FormattedMessage
               defaultMessage="knn algorithm"
               description="Name for the 'knn algorithm' extension"
               id="gui.extension.knnalgorithm.name"
           />
       ),
       extensionId: 'cxknn',
       iconURL: knnalgorithmImage,
       insetIconURL: knnalgorithmInsetImage,
       description: (
           <FormattedMessage
               defaultMessage="knn algorithm."
               description="Description for the 'knn algorithm' extension"
               id="gui.extension.knnalgorithm.description"
           />
       ),
       featured: true,
       helpLink: 'https://github.com/CodeLabClub/scratch3_knn'
},

 

查看目前npm 安裝套件的版本

npm -l 套件名稱 

例如:

npm ls @tensorflow-models/knn-classifier
scratch-gui@0.1.0 /home/teacher/音樂/osep_scratch-gui
└── @tensorflow-models/knn-classifier@1.2.2

大致上需要

    "@tensorflow-models/knn-classifier": "^1.2.2",
"@tensorflow/tfjs": "^0.13.5",
"@tensorflow/tfjs-converter": "^1.2.1",
"@tensorflow/tfjs-core": "^1.2.1",
"@tensorflow/tfjs-layers": "^0.8.5",
安裝特定版本

npm install @tensorflow/tfjs@0.10.0 

 npm  install 

@tensorflow-models/knn-classifier @tensorflow/tfjs @tensorflow/tfjs-converter @tensorflow/tfjs-core @tensorflow/tfjs-layers

沒有留言: