Skip to content

Commit

Permalink
Add ncnn test file (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzroeder committed Jun 26, 2024
1 parent 3b8357e commit aae584a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
40 changes: 24 additions & 16 deletions source/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -4954,8 +4954,11 @@ view.Context = class {
this._context = context;
this._tags = new Map();
this._content = new Map();
this._identifier = typeof identifier === 'string' ? identifier : context.identifier;
this._stream = stream || context.stream;
identifier = typeof identifier === 'string' ? identifier : context.identifier;
const index = Math.max(identifier.lastIndexOf('/'), identifier.lastIndexOf('\\'));
this._base = index === -1 ? undefined : identifier.substring(0, index);
this._identifier = index === -1 ? identifier : identifier.substring(index + 1);
}

get identifier() {
Expand All @@ -4971,7 +4974,7 @@ view.Context = class {
}

async fetch(file) {
const stream = await this._context.request(file, null);
const stream = await this._context.request(file, null, this._base);
return new view.Context(this, file, stream, new Map());
}

Expand Down Expand Up @@ -5337,20 +5340,25 @@ view.EntryContext = class {
}

async request(file, encoding, base) {
if (base === undefined) {
const stream = this._entries.get(file);
if (!stream) {
throw new view.Error('File not found.');
}
if (encoding) {
const decoder = new TextDecoder(encoding);
const buffer = stream.peek();
const value = decoder.decode(buffer);
return value;
}
return stream;
if (base === null) {
return this._host.request(file, encoding, base);
}
let stream = null;
if (typeof base === 'string') {
stream = this._entries.get(`${base}/${file}`) || this._entries.get(`${base}\\${file}`);
} else {
stream = this._entries.get(file);
}
if (!stream) {
throw new view.Error('File not found.');
}
if (encoding) {
const decoder = new TextDecoder(encoding);
const buffer = stream.peek();
const value = decoder.decode(buffer);
return value;
}
return this._host.request(file, encoding, base);
return stream;
}

async require(id) {
Expand Down Expand Up @@ -5638,7 +5646,7 @@ view.ModelFactoryService = class {
return true;
};
for (const format of formats) {
if (match(tags, format.tags)) {
if (match(tags, format.tags) && (!format.identifier || identifier === context.identifier)) {
const error = new view.Error(`Invalid file content. File contains ${format.name}.`);
error.context = context.identifier;
throw error;
Expand Down
8 changes: 8 additions & 0 deletions test/models.json
Original file line number Diff line number Diff line change
Expand Up @@ -3332,6 +3332,14 @@
"format": "ncnn",
"link": "https://github.com/lutzroeder/netron/issues/296"
},
{
"type": "ncnn",
"target": "darknet_yolov2.zip",
"source": "https://github.com/user-attachments/files/15981002/darknet_yolov2.zip",
"format": "ncnn",
"assert": [ "model.graphs[0].nodes[0].inputs[1].value[0].initializer.type.dataType == 'float32'" ],
"link": "https://github.com/lutzroeder/netron/issues/296"
},
{
"type": "ncnn",
"target": "darknet_yolov2.cfg.ncnn,darknet_yolov2.weights.ncnn",
Expand Down

0 comments on commit aae584a

Please sign in to comment.