Неправильно, когда я использую tenorflow и керас вместе? - PullRequest
0 голосов
/ 20 мая 2019

Это код, где я смешиваю тензорный поток с керасом.

def dense_block(x, nb_layers, nb_filter, growth_rate, bottleneck=False, dropout_rate=None, weight_decay=1e-4,
                  grow_nb_filters=True, return_concat_list=False):
    ''' Build a dense_block where the output of each conv_block is fed to subsequent ones
    Args:
        x: keras tensor
        nb_layers: the number of layers of conv_block to append to the model.
        nb_filter: number of filters
        growth_rate: growth rate
        bottleneck: bottleneck block
        dropout_rate: dropout rate
        weight_decay: weight decay factor
        grow_nb_filters: flag to decide to allow number of filters to grow
        return_concat_list: return the list of feature maps along with the actual output
    Returns: keras tensor with nb_layers of conv_block appended
    '''
    concat_axis = 1 if K.image_data_format() == 'channels_first' else -1
    x_list = [x]
    for i in range(nb_layers):
        cb = __conv_block(x, growth_rate, bottleneck, dropout_rate, weight_decay)
        ########################################################
        #This is where I mix tensorflow with keras.
        cb = K.reshape(cb,(-1,7*7*32))
        W = weight_variable([7*7*32,7*7*32])
        cb = tf.matmul(cb, W)
        cb = K.reshape(cb,(-1,7,7,32))
        x_list.append(cb)
        ######################################################
        x = concatenate([x, cb], axis=concat_axis)

        if grow_nb_filters:
            nb_filter += growth_rate
    if return_concat_list:
        return x, nb_filter, x_list
    else:
        return x, nb_filter

, но получаю ошибку, подобную этой:

AttributeError: у объекта 'Tensor' нет атрибута '_keras_history'

1 Ответ

0 голосов
/ 20 мая 2019

Вы не можете обычно смешивать отдельную установку кера с тензорным потоком, используя тот, который предоставляется в пределах tenoflow,

попробуйте заменить кера следующим образом from tensorflow import keras as K

https://www.tensorflow.org/api_docs/python/tf/keras
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...