質問編集履歴
3
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
document.getElementで取得した画像は以下コードでなぜreshapeされないのでしょうか?
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
reshape後はshape: [1, 100, 100, 3]に変更したいのですが。
|
6
10
|
|
7
11
|
|
8
12
|
|
2
変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
document.getElementByIdで取得した画像
|
1
|
+
document.getElementByIdで取得した画像がreshapeできない理由
|
test
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
下のhtmlから取得した画像を、JavaScriptで以下のように
|
1
|
+
下のhtmlから取得した画像を、JavaScriptで以下のようにreshapeしたのですが、変更されません。
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
document.getElementで取得した画像
|
5
|
+
document.getElementで取得した画像は以下コードでなぜreshapeされないのでしょうか?
|
6
6
|
|
7
7
|
|
8
8
|
|
@@ -26,58 +26,24 @@
|
|
26
26
|
|
27
27
|
const inputWidth = inputHeight = 100;
|
28
28
|
|
29
|
-
|
29
|
+
// resize
|
30
30
|
|
31
|
-
image
|
31
|
+
const image = document.getElementById('preview');
|
32
32
|
|
33
|
-
image.
|
33
|
+
image.height = 100;
|
34
34
|
|
35
|
-
|
35
|
+
image.width = 100;
|
36
36
|
|
37
|
-
|
37
|
+
let tensor = tf.browser.fromPixels(image).toFloat();
|
38
38
|
|
39
|
+
let offset = tf.scalar(255);
|
40
|
+
|
41
|
+
let tensor_iamge = tensor.div(offset).expandDims();
|
42
|
+
|
39
|
-
|
43
|
+
console.log(tensor_iamge);
|
40
44
|
|
41
45
|
|
42
46
|
|
43
|
-
|
47
|
+
>>>t {isDisposedInternal: false, shape: [1, 125, 100, 3], dtype: "float32", size: 37500, strides: [37500, 300, 3], …}
|
44
48
|
|
45
49
|
```
|
46
|
-
|
47
|
-
Error: pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement or ImageData, but was HTMLUnknownElement
|
48
|
-
|
49
|
-
```
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
備考
|
54
|
-
|
55
|
-
---
|
56
|
-
|
57
|
-
tf.fromPixelsは今は使えないようです
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
```
|
62
|
-
|
63
|
-
TypeError: tf.fromPixels is not a function.
|
64
|
-
|
65
|
-
```
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
また取得したimageのconsole.log(image.width)は100と出力されます。
|
70
|
-
|
71
|
-
```javascript
|
72
|
-
|
73
|
-
const image = document.getElementById('preview');
|
74
|
-
|
75
|
-
image.height = 100;
|
76
|
-
|
77
|
-
image.width = 100;
|
78
|
-
|
79
|
-
console.log(image.width);
|
80
|
-
|
81
|
-
>>> 100
|
82
|
-
|
83
|
-
```
|
1
編集
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
document.
|
1
|
+
document.getElementByIdで取得した画像をtensorに変換する方法
|
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
document.
|
5
|
+
document.getElementで取得した画像をtensorに変更するにはどうしたらいいでしょうか?
|
6
6
|
|
7
7
|
|
8
8
|
|
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
const inputWidth = inputHeight = 100;
|
28
28
|
|
29
|
-
const image = document.
|
29
|
+
const image = document.getElementById('preview');
|
30
30
|
|
31
31
|
image.height = inputHeight;
|
32
32
|
|
@@ -70,7 +70,7 @@
|
|
70
70
|
|
71
71
|
```javascript
|
72
72
|
|
73
|
-
const image = document.
|
73
|
+
const image = document.getElementById('preview');
|
74
74
|
|
75
75
|
image.height = 100;
|
76
76
|
|