小编the*_*ogh的帖子

如何加快 Keras 和 Tensorflow 中模型的加载?

假设我有大量训练有素的 keras 模型,我有时必须加载它们并进行预测。我需要以最快的方式加载每个模型并预测数据。我认为最快的解决方案是将它们存储在内存中,但是我想这不是一个好方法,因为不久之后 RAM 会溢出?所以在这一点上,我用这样的东西达到了最高的性能。

K.clear_session()
random_model = load_model('path/to/' + str(random_model))
results = random_model(final_input_row)
Run Code Online (Sandbox Code Playgroud)

此外,我有五个几乎一直使用的模型,在这种情况下,性能更为重要。我在启动服务器期间加载它们,并且可以持续访问它们。

graph = tf.get_default_graph()

with graph.as_default():

    constant_model = load_model(
            'path/to/constant_model')
Run Code Online (Sandbox Code Playgroud)

预言:

with graph.as_default():
    results = constant_model(final_input_row)
Run Code Online (Sandbox Code Playgroud)

问题是K.clear_session()我在加载期间执行的过程中random_models我从内存中丢失了它们。没有K.clear_session()加载random_models持续时间太长。你有什么想法我该如何解决这个问题?我什至可以使用完全不同的方法。

更新

我尝试做这样的事情:

class LoadModel:
    def __init__(self, path):
        self.path = path
        self.sess  = tf.Session(config=config)
        self.graph = tf.get_default_graph()
        K.set_session(self.sess)
        with self.graph.as_default():
            self.model = load_model(self.path)

    def do_predictions(self, x):
        with self.graph.as_default():
            return self.model.predict(x)
Run Code Online (Sandbox Code Playgroud)

然后当我执行时:

random_model = LoadModel('./path/to/random_model.h5')
results = random_model.do_predictions(final_input_row)
Run Code Online (Sandbox Code Playgroud)

预测数据大约需要 3 秒钟。在random_models我有很多模型的情况下,这是可以接受的。然而, …

python django django-rest-framework keras tensorflow

5
推荐指数
1
解决办法
4245
查看次数

如何在 Angular 6 中显示以 base64 格式编码的图像?

我正在努力解决与 Angular 6 相关的问题并显示以 base64 格式编码的图像。任何想法为什么下面显示的代码不显示图像?

html:

<tr *ngFor="let row of this.UploaderService.tableImageRecognition.dataRows">
<img src="{{this.hello}}" />
Run Code Online (Sandbox Code Playgroud)

ts:

this.hello = "data:image/png;base64, /9j/4AAQSkZJRgABAQAAA..."
Run Code Online (Sandbox Code Playgroud)

虽然下面显示的代码可以正常工作并显示图片?

html:

<tr *ngFor="let row of this.UploaderService.tableImageRecognition.dataRows">
<!--<img src="data:image/png;base64, /9j/4AAQSkZJRgABAQAAA..."/>
Run Code Online (Sandbox Code Playgroud)

this.hello在构造函数中分配只是为了测试目的。我以这种方式创建它this.hello = 'data:image/png;base64, ' + this.UploaderService.imageRecognitionRowsData[0].toString()我的主要目标是imageRecognitionRowsData在这个循环中显示<tr *ngFor="let row of this.UploaderService.tableImageRecognition.dataRows">。因此,对于第一次迭代,我将显示图像,imageRecognitionRowsData[0]然后在下一次迭代图像imageRecognitionRowsData[1]等期间显示图像。的长度this.UploaderService.tableImageRecognition.dataRows始终与this.UploaderService.imageRecognitionRowsData添加时相同,我<p>{{this.hello}}</p>在 html 中得到相同的字符串。我不知道出了什么问题。我也试图与this.hello2 = this.sanitizer.bypassSecurityTrustResourceUrl(this.hello);this.hello2 = this.sanitizer.bypassSecurityTrustUrl(this.hello);<img [src]="this.hello" />等但没有任何工程。任何想法如何解决这个问题?

html base64 typescript angular angular6

4
推荐指数
2
解决办法
3万
查看次数

如何使用Angular 5下载文件?

当我粘贴my_example_link到浏览器中时,文件会以适当的方式自动下载。但是,当我使用下面显示的源代码时,下载不起作用。单击download按钮后,我想下载文件。任何想法有什么问题吗?我没有任何错误。

user.service.ts:

DownloadFiles() {

    return this.http.get('my_example_link', {responseType: 'text'});

}
Run Code Online (Sandbox Code Playgroud)

uploader.service.ts:

DownloadFile(){

      this.userService.DownloadFiles()
          .subscribe(
              (data) => this.downloadFile2(data)), // console.log(data),
              (error) => console.log("Error downloading the file."),
              () => console.info("OK");
}

downloadFile2(data: Response){
  var blob = new Blob([data], { type: 'text/csv' });
  var url= window.URL.createObjectURL(blob);
  window.open(url);
}
Run Code Online (Sandbox Code Playgroud)

something.component.html:

<li class="nav-item" *ngIf="isCloud()">
    <a  (click)="this.UploaderService.DownloadFile()" download="file23.txt" style='cursor: pointer;' class="nav-link" target="_blank">
        <i class="nc-icon nc-basket"></i> Download
    </a>
</li>
Run Code Online (Sandbox Code Playgroud)

html html5 typescript angular angular5

3
推荐指数
1
解决办法
9599
查看次数

斜杠在 Elasticsearch 中使用正则表达式匹配查询时不起作用

Elasticsearch 官方文档中有这样写Any reserved character can be escaped with a backslash "\*" including a literal backslash character: "\\"

你能解释一下为什么这样查询吗

{
                    "query": {
                        "bool": {
                            "must": [
                                {
                                    "regexp": {
                                        "path": ".*test\/test.txt.*"
                                    }
                                },
                                {
                                    "match": {
                                        "user_id": 1
                                    }
                                }
                            ]
                        }
                    }
                }
Run Code Online (Sandbox Code Playgroud)

找不到这样的索引

{
                "_index": "pictures",
                "_type": "picture",
                "_id": "wiskQ2kBi923Omj4U",
                "_score": 1,
                "_source": {
                    "user_id": 1,
                    "tag": [],
                    "text": "some text",
                    "path": "test/test.txt"
                }
            }
Run Code Online (Sandbox Code Playgroud)

regex indexing elasticsearch elasticsearch-query elastic-stack

2
推荐指数
1
解决办法
2687
查看次数