我正在运行一个Heroku应用,该应用获取YouTube视频标题并将其输出到数据集文件,然后从数据集中生成一批标题。我正在使用tensorflow 2.0.0。
当我部署应用程序并查看日志(Heroku CLI)时,出现以下错误:
2020-06-09T09:20:02.871756+00:00 app[worker.1]: File "__main__.py", line 1, in <module>
2020-06-09T09:20:02.871757+00:00 app[worker.1]: from trainer import train_function
2020-06-09T09:20:02.871757+00:00 app[worker.1]: File "/app/trainer.py", line 6, in <module>
2020-06-09T09:20:02.871758+00:00 app[worker.1]: textgen = textgenrnn(name="./outputs/" + model_name)
2020-06-09T09:20:02.871759+00:00 app[worker.1]: File "/app/textgenrnn/textgenrnn.py", line 81, in __init__
2020-06-09T09:20:02.871765+00:00 app[worker.1]: weights_path=weights_path)
2020-06-09T09:20:02.871765+00:00 app[worker.1]: File "/app/textgenrnn/model.py", line 30, in textgenrnn_model
2020-06-09T09:20:02.871766+00:00 app[worker.1]: rnn_layer_list.append(new_rnn(cfg, i+1)(prev_layer))
2020-06-09T09:20:02.871766+00:00 app[worker.1]: File "/app/textgenrnn/model.py", line 79, in new_rnn
2020-06-09T09:20:02.871767+00:00 app[worker.1]: use_cudnnlstm = K.backend() == 'tensorflow' and len(config.get_visible_devices('GPU')) > 0
2020-06-09T09:20:02.871768+00:00 app[worker.1]: AttributeError: module 'tensorflow_core._api.v2.config' has no attribute 'get_visible_devices'
这些是我的文件和其中的代码:
__main__.py
from trainer import train_function
from generator import *
from config import *
import requests
train_function(
file_path="./datasets/" + file_name,
new_model=True,
num_epochs=train_cfg['num_epochs'],
gen_epochs=train_cfg['gen_epochs'],
batch_size=1024,
train_size=train_cfg['train_size'],
dropout=train_cfg['dropout'],
validation=train_cfg['validation'],
is_csv=train_cfg['is_csv'],
rnn_layers=model_cfg['rnn_layers'],
rnn_size=model_cfg['rnn_size'],
rnn_bidirectional=model_cfg['rnn_bidirectional'],
max_length=model_cfg['max_length'],
dim_embeddings=100,
word_level=model_cfg['word_level'])
textgen.generate_to_file("./outputs/" + gen_file,
temperature=temperature,
prefix=prefix,
n=n,
max_gen_length=max_gen_length)
config.py
model_cfg = {
'word_level': True, # set to True if want to train a word-level model (requires more data and smaller max_length)
'rnn_size': 128, # number of LSTM cells of each layer (128/256 recommended)
'rnn_layers': 4, # number of LSTM layers (>=2 recommended)
'rnn_bidirectional': True, # consider text both forwards and backward, can give a training boost
'max_length': 8,
# number of tokens to consider before predicting the next (20-40 for characters, 5-10 for words recommended)
'max_words': 100000, # maximum number of words to model; the rest will be ignored (word-level model only)
"weights_path": "./outputs/"
}
train_cfg = {
'line_delimited': True, # set to True if each text has its own line in the source file
'num_epochs': 512, # set higher to train the model for longer
'gen_epochs': 6, # generates sample text from model after given number of epochs
'train_size': 1, # proportion of input data to train on: setting < 1.0 limits model from learning perfectly
'dropout': 0.0, # ignore a random proportion of source tokens each epoch, allowing model to generalize better
'validation': True, # If train__size < 1.0, test on holdout dataset; will make overall training slower
'is_csv': False, # set to True if file is a CSV exported from Excel/BigQuery/pandas
"weights_path": "./outputs/"
}
file_name = "didntactlyhappn_dataset.txt"
model_name = "didntactlyhappn"
还有trainer.py
from textgenrnn import textgenrnn
from config import *
textgen = textgenrnn(name="./outputs/" + model_name)
train_function = textgen.train_from_file if train_cfg['line_delimited'] else textgen.train_from_largetext_file
答案 0 :(得分:0)
我使用tensorflow == 2.0.0。
AttributeError: module 'tensorflow_core._api.v2.config' has no attribute 'get_visible_devices'
tensorflow==2.0.0
没有get_visible_devices
tensorflow==2.2.0
有get_visible_devices
请参阅:
https://www.tensorflow.org/api_docs/python/tf/config/get_visible_devices
https://www.tensorflow.org/versions/r2.0/api_docs/python/tf