Stylistic

This commit is contained in:
Manav Rathi 2024-04-30 18:53:17 +05:30
parent 76c98bdf32
commit 50a1447020
No known key found for this signature in database
5 changed files with 14 additions and 15 deletions

View file

@ -5,8 +5,7 @@ module.exports = {
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/strict-type-checked",
/* What we really want eventually */
// "plugin:@typescript-eslint/stylistic-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
],
plugins: ["@typescript-eslint"],
parser: "@typescript-eslint/parser",

View file

@ -45,7 +45,7 @@ const clipImageEmbedding_ = async (jpegFilePath: string) => {
`onnx/clip image embedding took ${Date.now() - t1} ms (prep: ${t2 - t1} ms, inference: ${Date.now() - t2} ms)`,
);
/* Need these model specific casts to type the result */
const imageEmbedding = ensure(results["output"]).data as Float32Array;
const imageEmbedding = ensure(results.output).data as Float32Array;
return normalizeEmbedding(imageEmbedding);
};
@ -120,13 +120,12 @@ const getRGBData = async (jpegFilePath: string): Promise<number[]> => {
const normalizeEmbedding = (embedding: Float32Array) => {
let normalization = 0;
for (let index = 0; index < embedding.length; index++) {
normalization += ensure(embedding[index]) * ensure(embedding[index]);
}
for (const v of embedding) normalization += v * v;
const sqrtNormalization = Math.sqrt(normalization);
for (let index = 0; index < embedding.length; index++) {
for (let index = 0; index < embedding.length; index++)
embedding[index] = ensure(embedding[index]) / sqrtNormalization;
}
return embedding;
};
@ -168,6 +167,6 @@ export const clipTextEmbeddingIfAvailable = async (text: string) => {
() =>
`onnx/clip text embedding took ${Date.now() - t1} ms (prep: ${t2 - t1} ms, inference: ${Date.now() - t2} ms)`,
);
const textEmbedding = ensure(results["output"]).data as Float32Array;
const textEmbedding = ensure(results.output).data as Float32Array;
return normalizeEmbedding(textEmbedding);
};

View file

@ -24,7 +24,7 @@ export const detectFaces = async (input: Float32Array) => {
};
const results = await session.run(feeds);
log.debug(() => `onnx/yolo face detection took ${Date.now() - t} ms`);
return ensure(results["output"]).data;
return ensure(results.output).data;
};
const cachedFaceEmbeddingSession = makeCachedInferenceSession(
@ -47,7 +47,6 @@ export const faceEmbedding = async (input: Float32Array) => {
const results = await session.run(feeds);
log.debug(() => `onnx/yolo face embedding took ${Date.now() - t} ms`);
/* Need these model specific casts to extract and type the result */
return (results.embeddings as unknown as Record<string, unknown>)[
"cpuData"
] as Float32Array;
return (results.embeddings as unknown as Record<string, unknown>)
.cpuData as Float32Array;
};

View file

@ -14,7 +14,7 @@ export const listZipItems = async (zipPath: string): Promise<ZipItem[]> => {
for (const entry of Object.values(entries)) {
const basename = path.basename(entry.name);
// Ignore "hidden" files (files whose names begins with a dot).
if (entry.isFile && basename.length > 0 && basename[0] != ".") {
if (entry.isFile && basename.startsWith(".")) {
// `entry.name` is the path within the zip.
entryNames.push(entry.name);
}

View file

@ -98,7 +98,9 @@ export const makeFileForDataOrPathOrZipItem = async (
): Promise<FileForDataOrPathOrZipItem> => {
let path: string;
let isFileTemporary: boolean;
let writeToTemporaryFile = async () => {};
let writeToTemporaryFile = async () => {
/* no-op */
};
if (typeof dataOrPathOrZipItem == "string") {
path = dataOrPathOrZipItem;