深度学习

深度学习

多线程调用yolo模型会出错(包括使用cv2载入yolo模型)

深度学习李魔佛 发表了文章 • 0 个评论 • 10 次浏览 • 2019-12-05 10:27 • 来自相关话题

占坑。
 
多线程调用yolo模型会出错(包括使用cv2载入yolo模型)
 
占坑。
 
多线程调用yolo模型会出错(包括使用cv2载入yolo模型)
 

keras yolo物体检测 入门教程

深度学习李魔佛 发表了文章 • 0 个评论 • 34 次浏览 • 2019-11-28 16:03 • 来自相关话题

占坑
占坑

RuntimeError: `get_session` is not available when using TensorFlow 2.0.

深度学习李魔佛 发表了文章 • 0 个评论 • 158 次浏览 • 2019-11-28 15:10 • 来自相关话题

这个问题是TensorFlow版本问题,在2.0以上get_session是被移除了。需要做一些修改,或者把tf降级。可以安装1.15版本
pip install tensorflow==1.15 --upgradeHere, we will see how we can upgrade our code to work with tensorflow 2.0.

This error is usually faced when we are loading pre-trained model with tensorflow session/graph or we are building flask api over a pre-trained model and loading model in tensorflow graph to avoid collision of sessions while application is getting multiple requests at once or say in case of multi-threadinng

After tensorflow 2.0 upgrade, i also started facing above error in one of my project when i had built api of pre-trained model with flask. So i looked around in tensorflow 2.0 documents to find a workaround, to avoid this runtime error and upgrade my code to work with tensorflow 2.0 as well rather than downgrading it to tensorflow 1.x .

I had a project on which i had written tutorial as well on how to build Flask api on trained keras model of text classification and then use it in production

But this project was not working after tensorflow upgrade and was facing runtime error.

Stacktrace of error was something like below:

File "/Users/Upasana/Documents/playground/deploy-keras-model-in-production/src/main.py", line 37, in model_predict
with backend.get_session().graph.as_default() as g:
File "/Users/Upasana/Documents/playground/deploy-keras-model-in-production/venv-tf2/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 379, in get_session
'`get_session` is not available '
RuntimeError: `get_session` is not available when using TensorFlow 2.0.
Related code to get model
with backend.get_session().graph.as_default() as g:
model = SentimentService.get_model1()
Related code to load model
def load_deep_model(self, model):
json_file = open('./src/mood-saved-models/' + model + '.json', 'r')
loaded_model_json = json_file.read()
loaded_model = model_from_json(loaded_model_json)

loaded_model.load_weights("./src/mood-saved-models/" + model + ".h5")

loaded_model._make_predict_function()
return loaded_model
get_session is removed in tensorflow 2.0 and hence not available.

so, in order to load saved model we switched methods. Rather than using keras’s load_model, we used tensorflow to load model so that we can load model using distribution strategy.

Note
The tf.distribute.Strategy API provides an abstraction for distributing your training across multiple processing units.

New code to get model
another_strategy = tf.distribute.MirroredStrategy()
with another_strategy.scope():
model = SentimentService.get_model1()
New code to load model
def load_deep_model(self, model):
loaded_model = tf.keras.models.load_model("./src/mood-saved-models/"model + ".h5")
return loaded_model
This worked and solved the problem with runtime error of get_session not available in tensorflow 2.0 . You can refer to Tensorflow 2.0 upgraded article too

Hope, this will solve your problem too. Thanks for following this article. 查看全部
这个问题是TensorFlow版本问题,在2.0以上get_session是被移除了。需要做一些修改,或者把tf降级。可以安装1.15版本
pip install tensorflow==1.15 --upgrade
Here, we will see how we can upgrade our code to work with tensorflow 2.0.

This error is usually faced when we are loading pre-trained model with tensorflow session/graph or we are building flask api over a pre-trained model and loading model in tensorflow graph to avoid collision of sessions while application is getting multiple requests at once or say in case of multi-threadinng

After tensorflow 2.0 upgrade, i also started facing above error in one of my project when i had built api of pre-trained model with flask. So i looked around in tensorflow 2.0 documents to find a workaround, to avoid this runtime error and upgrade my code to work with tensorflow 2.0 as well rather than downgrading it to tensorflow 1.x .

I had a project on which i had written tutorial as well on how to build Flask api on trained keras model of text classification and then use it in production

But this project was not working after tensorflow upgrade and was facing runtime error.

Stacktrace of error was something like below:

File "/Users/Upasana/Documents/playground/deploy-keras-model-in-production/src/main.py", line 37, in model_predict
with backend.get_session().graph.as_default() as g:
File "/Users/Upasana/Documents/playground/deploy-keras-model-in-production/venv-tf2/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 379, in get_session
'`get_session` is not available '
RuntimeError: `get_session` is not available when using TensorFlow 2.0.
Related code to get model
with backend.get_session().graph.as_default() as g:
model = SentimentService.get_model1()
Related code to load model
def load_deep_model(self, model):
json_file = open('./src/mood-saved-models/' + model + '.json', 'r')
loaded_model_json = json_file.read()
loaded_model = model_from_json(loaded_model_json)

loaded_model.load_weights("./src/mood-saved-models/" + model + ".h5")

loaded_model._make_predict_function()
return loaded_model
get_session is removed in tensorflow 2.0 and hence not available.

so, in order to load saved model we switched methods. Rather than using keras’s load_model, we used tensorflow to load model so that we can load model using distribution strategy.

Note
The tf.distribute.Strategy API provides an abstraction for distributing your training across multiple processing units.

New code to get model
another_strategy = tf.distribute.MirroredStrategy()
with another_strategy.scope():
model = SentimentService.get_model1()
New code to load model
def load_deep_model(self, model):
loaded_model = tf.keras.models.load_model("./src/mood-saved-models/"model + ".h5")
return loaded_model
This worked and solved the problem with runtime error of get_session not available in tensorflow 2.0 . You can refer to Tensorflow 2.0 upgraded article too

Hope, this will solve your problem too. Thanks for following this article.

sklearn中的Bunch数据类型

深度学习李魔佛 发表了文章 • 0 个评论 • 4935 次浏览 • 2018-06-07 19:10 • 来自相关话题

在sklearn中自带部分数据 如 datasets 包中




 
那么这个
<class 'sklearn.utils.Bunch'>
是什么数据格式 ?
 
打印一下:




好吧,原来就是一个字典结构。可以像调用字典一样使用Bunch。
比如 data['image'] 就获取 key为image的内容。
 

原创地址:http://30daydo.com/article/325 
欢迎转载,请注明出处。 查看全部
在sklearn中自带部分数据 如 datasets 包中
k1.PNG

 
那么这个
<class 'sklearn.utils.Bunch'>
是什么数据格式 ?
 
打印一下:
k3.PNG

好吧,原来就是一个字典结构。可以像调用字典一样使用Bunch。
比如 data['image'] 就获取 key为image的内容。
 

原创地址:http://30daydo.com/article/325 
欢迎转载,请注明出处。

sklearn中SGDClassifier分类器每次得到的结果都不一样?

深度学习李魔佛 发表了文章 • 0 个评论 • 2191 次浏览 • 2018-06-07 17:14 • 来自相关话题

如下代码:sgdc = SGDClassifier()
sgdc.fit(X_train,y_train)
sgdc_predict_y = sgdc.predict(X_test)
print 'Accuary of SGD classifier ', sgdc.score(X_test,y_test)
print classification_report(y_test,sgdc_predict_y,target_names=['Benign','Malignant'])
每次输出的结果都不一样? WHY
 
 
因为你使用了一个默认参数:
SGDClassifier(random_state = None)
 
所以这个随机种子每次不一样,所以得到的结果就可能不一样,如果你指定随机种子值,那么每次得到的结果都是一样的了。
 

原创地址:http://30daydo.com/article/323 
欢迎转载,请注明出处。 查看全部
如下代码:
sgdc = SGDClassifier()
sgdc.fit(X_train,y_train)
sgdc_predict_y = sgdc.predict(X_test)
print 'Accuary of SGD classifier ', sgdc.score(X_test,y_test)
print classification_report(y_test,sgdc_predict_y,target_names=['Benign','Malignant'])

每次输出的结果都不一样? WHY
 
 
因为你使用了一个默认参数:
SGDClassifier(random_state = None)
 
所以这个随机种子每次不一样,所以得到的结果就可能不一样,如果你指定随机种子值,那么每次得到的结果都是一样的了。
 

原创地址:http://30daydo.com/article/323 
欢迎转载,请注明出处。

多线程调用yolo模型会出错(包括使用cv2载入yolo模型)

深度学习李魔佛 发表了文章 • 0 个评论 • 10 次浏览 • 2019-12-05 10:27 • 来自相关话题

占坑。
 
多线程调用yolo模型会出错(包括使用cv2载入yolo模型)
 
占坑。
 
多线程调用yolo模型会出错(包括使用cv2载入yolo模型)
 

keras yolo物体检测 入门教程

深度学习李魔佛 发表了文章 • 0 个评论 • 34 次浏览 • 2019-11-28 16:03 • 来自相关话题

占坑
占坑

RuntimeError: `get_session` is not available when using TensorFlow 2.0.

深度学习李魔佛 发表了文章 • 0 个评论 • 158 次浏览 • 2019-11-28 15:10 • 来自相关话题

这个问题是TensorFlow版本问题,在2.0以上get_session是被移除了。需要做一些修改,或者把tf降级。可以安装1.15版本
pip install tensorflow==1.15 --upgradeHere, we will see how we can upgrade our code to work with tensorflow 2.0.

This error is usually faced when we are loading pre-trained model with tensorflow session/graph or we are building flask api over a pre-trained model and loading model in tensorflow graph to avoid collision of sessions while application is getting multiple requests at once or say in case of multi-threadinng

After tensorflow 2.0 upgrade, i also started facing above error in one of my project when i had built api of pre-trained model with flask. So i looked around in tensorflow 2.0 documents to find a workaround, to avoid this runtime error and upgrade my code to work with tensorflow 2.0 as well rather than downgrading it to tensorflow 1.x .

I had a project on which i had written tutorial as well on how to build Flask api on trained keras model of text classification and then use it in production

But this project was not working after tensorflow upgrade and was facing runtime error.

Stacktrace of error was something like below:

File "/Users/Upasana/Documents/playground/deploy-keras-model-in-production/src/main.py", line 37, in model_predict
with backend.get_session().graph.as_default() as g:
File "/Users/Upasana/Documents/playground/deploy-keras-model-in-production/venv-tf2/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 379, in get_session
'`get_session` is not available '
RuntimeError: `get_session` is not available when using TensorFlow 2.0.
Related code to get model
with backend.get_session().graph.as_default() as g:
model = SentimentService.get_model1()
Related code to load model
def load_deep_model(self, model):
json_file = open('./src/mood-saved-models/' + model + '.json', 'r')
loaded_model_json = json_file.read()
loaded_model = model_from_json(loaded_model_json)

loaded_model.load_weights("./src/mood-saved-models/" + model + ".h5")

loaded_model._make_predict_function()
return loaded_model
get_session is removed in tensorflow 2.0 and hence not available.

so, in order to load saved model we switched methods. Rather than using keras’s load_model, we used tensorflow to load model so that we can load model using distribution strategy.

Note
The tf.distribute.Strategy API provides an abstraction for distributing your training across multiple processing units.

New code to get model
another_strategy = tf.distribute.MirroredStrategy()
with another_strategy.scope():
model = SentimentService.get_model1()
New code to load model
def load_deep_model(self, model):
loaded_model = tf.keras.models.load_model("./src/mood-saved-models/"model + ".h5")
return loaded_model
This worked and solved the problem with runtime error of get_session not available in tensorflow 2.0 . You can refer to Tensorflow 2.0 upgraded article too

Hope, this will solve your problem too. Thanks for following this article. 查看全部
这个问题是TensorFlow版本问题,在2.0以上get_session是被移除了。需要做一些修改,或者把tf降级。可以安装1.15版本
pip install tensorflow==1.15 --upgrade
Here, we will see how we can upgrade our code to work with tensorflow 2.0.

This error is usually faced when we are loading pre-trained model with tensorflow session/graph or we are building flask api over a pre-trained model and loading model in tensorflow graph to avoid collision of sessions while application is getting multiple requests at once or say in case of multi-threadinng

After tensorflow 2.0 upgrade, i also started facing above error in one of my project when i had built api of pre-trained model with flask. So i looked around in tensorflow 2.0 documents to find a workaround, to avoid this runtime error and upgrade my code to work with tensorflow 2.0 as well rather than downgrading it to tensorflow 1.x .

I had a project on which i had written tutorial as well on how to build Flask api on trained keras model of text classification and then use it in production

But this project was not working after tensorflow upgrade and was facing runtime error.

Stacktrace of error was something like below:

File "/Users/Upasana/Documents/playground/deploy-keras-model-in-production/src/main.py", line 37, in model_predict
with backend.get_session().graph.as_default() as g:
File "/Users/Upasana/Documents/playground/deploy-keras-model-in-production/venv-tf2/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 379, in get_session
'`get_session` is not available '
RuntimeError: `get_session` is not available when using TensorFlow 2.0.
Related code to get model
with backend.get_session().graph.as_default() as g:
model = SentimentService.get_model1()
Related code to load model
def load_deep_model(self, model):
json_file = open('./src/mood-saved-models/' + model + '.json', 'r')
loaded_model_json = json_file.read()
loaded_model = model_from_json(loaded_model_json)

loaded_model.load_weights("./src/mood-saved-models/" + model + ".h5")

loaded_model._make_predict_function()
return loaded_model
get_session is removed in tensorflow 2.0 and hence not available.

so, in order to load saved model we switched methods. Rather than using keras’s load_model, we used tensorflow to load model so that we can load model using distribution strategy.

Note
The tf.distribute.Strategy API provides an abstraction for distributing your training across multiple processing units.

New code to get model
another_strategy = tf.distribute.MirroredStrategy()
with another_strategy.scope():
model = SentimentService.get_model1()
New code to load model
def load_deep_model(self, model):
loaded_model = tf.keras.models.load_model("./src/mood-saved-models/"model + ".h5")
return loaded_model
This worked and solved the problem with runtime error of get_session not available in tensorflow 2.0 . You can refer to Tensorflow 2.0 upgraded article too

Hope, this will solve your problem too. Thanks for following this article.

sklearn中的Bunch数据类型

深度学习李魔佛 发表了文章 • 0 个评论 • 4935 次浏览 • 2018-06-07 19:10 • 来自相关话题

在sklearn中自带部分数据 如 datasets 包中




 
那么这个
<class 'sklearn.utils.Bunch'>
是什么数据格式 ?
 
打印一下:




好吧,原来就是一个字典结构。可以像调用字典一样使用Bunch。
比如 data['image'] 就获取 key为image的内容。
 

原创地址:http://30daydo.com/article/325 
欢迎转载,请注明出处。 查看全部
在sklearn中自带部分数据 如 datasets 包中
k1.PNG

 
那么这个
<class 'sklearn.utils.Bunch'>
是什么数据格式 ?
 
打印一下:
k3.PNG

好吧,原来就是一个字典结构。可以像调用字典一样使用Bunch。
比如 data['image'] 就获取 key为image的内容。
 

原创地址:http://30daydo.com/article/325 
欢迎转载,请注明出处。

sklearn中SGDClassifier分类器每次得到的结果都不一样?

深度学习李魔佛 发表了文章 • 0 个评论 • 2191 次浏览 • 2018-06-07 17:14 • 来自相关话题

如下代码:sgdc = SGDClassifier()
sgdc.fit(X_train,y_train)
sgdc_predict_y = sgdc.predict(X_test)
print 'Accuary of SGD classifier ', sgdc.score(X_test,y_test)
print classification_report(y_test,sgdc_predict_y,target_names=['Benign','Malignant'])
每次输出的结果都不一样? WHY
 
 
因为你使用了一个默认参数:
SGDClassifier(random_state = None)
 
所以这个随机种子每次不一样,所以得到的结果就可能不一样,如果你指定随机种子值,那么每次得到的结果都是一样的了。
 

原创地址:http://30daydo.com/article/323 
欢迎转载,请注明出处。 查看全部
如下代码:
sgdc = SGDClassifier()
sgdc.fit(X_train,y_train)
sgdc_predict_y = sgdc.predict(X_test)
print 'Accuary of SGD classifier ', sgdc.score(X_test,y_test)
print classification_report(y_test,sgdc_predict_y,target_names=['Benign','Malignant'])

每次输出的结果都不一样? WHY
 
 
因为你使用了一个默认参数:
SGDClassifier(random_state = None)
 
所以这个随机种子每次不一样,所以得到的结果就可能不一样,如果你指定随机种子值,那么每次得到的结果都是一样的了。
 

原创地址:http://30daydo.com/article/323 
欢迎转载,请注明出处。