Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions tfjs-converter/python/tensorflowjs/op_list/control.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
{
"start": 0,
"name": "tensorArrayId",
"type": "number"
"type": "tensor"
},
{
"start": 1,
Expand Down Expand Up @@ -189,7 +189,7 @@
{
"start": 0,
"name": "tensorArrayId",
"type": "number"
"type": "tensor"
},
{
"start": 1,
Expand Down Expand Up @@ -218,7 +218,7 @@
{
"start": 0,
"name": "tensorArrayId",
"type": "number"
"type": "tensor"
},
{
"start": 1,
Expand Down Expand Up @@ -251,7 +251,7 @@
{
"start": 0,
"name": "tensorArrayId",
"type": "number"
"type": "tensor"
},
{
"start": 1,
Expand Down Expand Up @@ -284,7 +284,7 @@
{
"start": 0,
"name": "tensorArrayId",
"type": "number"
"type": "tensor"
},
{
"start": 1,
Expand Down Expand Up @@ -313,7 +313,7 @@
{
"start": 0,
"name": "tensorArrayId",
"type": "number"
"type": "tensor"
},
{
"start": 1,
Expand Down Expand Up @@ -346,7 +346,7 @@
{
"start": 0,
"name": "tensorArrayId",
"type": "number"
"type": "tensor"
},
{
"start": 1,
Expand All @@ -362,7 +362,7 @@
{
"start": 0,
"name": "tensorArrayId",
"type": "number"
"type": "tensor"
}
]
},
Expand Down Expand Up @@ -540,7 +540,7 @@
{
"start": 0,
"name": "tensorListId",
"type": "number"
"type": "tensor"
},
{
"start": 1,
Expand Down Expand Up @@ -568,7 +568,7 @@
{
"start": 0,
"name": "tensorListId",
"type": "number"
"type": "tensor"
},
{
"start": 1,
Expand Down Expand Up @@ -596,7 +596,7 @@
{
"start": 0,
"name": "tensorListId",
"type": "number"
"type": "tensor"
},
{
"start": 1,
Expand Down Expand Up @@ -670,7 +670,7 @@
{
"start": 0,
"name": "tensorListId",
"type": "number"
"type": "tensor"
},
{
"start": 1,
Expand Down Expand Up @@ -726,7 +726,7 @@
{
"start": 0,
"name": "tensorListId",
"type": "number"
"type": "tensor"
}
],
"attrs": [
Expand All @@ -749,7 +749,7 @@
{
"start": 0,
"name": "tensorListId",
"type": "number"
"type": "tensor"
},
{
"start": 1,
Expand All @@ -772,7 +772,7 @@
{
"start": 0,
"name": "tensorListId",
"type": "number"
"type": "tensor"
},
{
"start": 1,
Expand Down
9 changes: 5 additions & 4 deletions tfjs-converter/src/executor/tensor_array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ export interface TensorWithState {
* allows reading from the array and writing to the array.
*/
export class TensorArray {
private static nextId = 0;
private tensors: TensorWithState[] = [];
private closed_ = false;
readonly id: number;
readonly idTensor: Tensor;
constructor(
readonly name: string, readonly dtype: DataType, private maxSize: number,
private elementShape: number[], readonly identicalElementShapes: boolean,
readonly dynamicSize: boolean, readonly clearAfterRead: boolean) {
this.id = TensorArray.nextId++;
this.idTensor = scalar(this.id);
this.idTensor = scalar(0);
keep(this.idTensor);
}

get id() {
return this.idTensor.id;
}

get closed() {
return this.closed_;
}
Expand Down
28 changes: 17 additions & 11 deletions tfjs-converter/src/executor/tensor_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ import {assertShapesMatchAllowUndefinedSize} from './tensor_utils';
*/

export class TensorList {
private static nextId = 0;
readonly id: number;
readonly idTensor: Tensor;
maxNumElements: number;

get id() {
return this.idTensor.id;
}
/**
*
* @param tensors list of tensors
Expand All @@ -51,9 +52,19 @@ export class TensorList {
constructor(
readonly tensors: Tensor[], readonly elementShape: number[],
readonly elementDtype: DataType, maxNumElements = -1) {
tensors.forEach(tensor => keep(tensor));
this.id = TensorList.nextId++;
this.idTensor = scalar(this.id);
if (tensors != null) {
tensors.forEach(tensor => {
if (elementDtype !== tensor.dtype) {
throw new Error(`Invalid data types; op elements ${
elementDtype}, but list elements ${tensor.dtype}`);
}
assertShapesMatchAllowUndefinedSize(
elementShape, tensor.shape, 'TensorList shape mismatch: ');

keep(tensor);
});
}
this.idTensor = scalar(0);
this.maxNumElements = maxNumElements;
keep(this.idTensor);
}
Expand Down Expand Up @@ -293,12 +304,7 @@ export function fromTensor(
assertShapesMatchAllowUndefinedSize(
outputShape, elementShape, 'TensorList shape mismatch: ');

const tensorList: Tensor[] = [];
for (let i = 0; i < tensor.shape[0]; ++i) {
const tmp = tensor.slice(i, 1);
tensorList.push(tmp.reshape(outputShape));
tmp.dispose();
}
const tensorList: Tensor[] = tensor.unstack();
return new TensorList(tensorList, elementShape, dtype);
}

Expand Down
Loading