我正在使用此代码来获取刚刚上传的图像"使用 fileReady(e) {
let file: File = e[0];
let image = new Image();
let src: string;
image.onload = function () {
src = image.src;
//do something with image
}.bind(this);
src = URL.createObjectURL(file);
image.src = src;
}
进入浏览器并将数据发送到使用它的某个组件。
Video()
这适用于图像。下一个目标是让它也适用于视频。很遗憾,没有HTMLVideoElement
构造函数,def cross_entropy(predictions, targets, epsilon=1e-12):
"""
Computes cross entropy between targets (encoded as one-hot vectors)
and predictions.
Input: predictions (N, k) ndarray
targets (N, k) ndarray
Returns: scalar
"""
predictions = np.clip(predictions, epsilon, 1. - epsilon)
N = predictions.shape[0]
ce = -np.sum(targets*np.log(predictions+1e-9))/N
return ce
predictions = np.array([[0.25,0.25,0.25,0.25],
[0.01,0.01,0.01,0.96]])
targets = np.array([[0,0,0,1],
[0,0,0,1]])
ans = 0.71355817782 #Correct answer
x = cross_entropy(predictions, targets)
print(np.isclose(x,ans))
也没有做到这一点。我应该如何重写此代码以便它可以处理视频?
答案 0 :(得分:2)
像这样:
fileReady(e) {
const file: File = e[0];
const fileReader = new FileReader();
fileReader.onloadend = (event: any) => {
const arrayBuffer = event.target.result;
const fileType = "video/mpeg";
const blob = new Blob(arrayBuffer , {type: fileType });
const src = URL.createObjectURL(blob);
video.src = src;
};
fileReader.readAsArrayBuffer(file);
}
答案 1 :(得分:0)
只需在答案中添加最新更新,
const blob = new Blob(arrayBuffer , {type: fileType });
将给出Blob需要可迭代的错误。 因此解决方法是:
const blob = new Blob([arrayBuffer], {type: fileType });