Tensorflow возвращает ошибку OperatorNotAllowedInGraphErrorTraceback, когда я запускаю на colab тот же код, что и два месяца назад - PullRequest
0 голосов
/ 28 апреля 2020

Я разработал программное обеспечение, вдохновленное работой, опубликованной на github в 2018 году (https://github.com/simeon-spasov/MCI). До прошлого месяца, используя Google Colab, это работало! Но теперь Colab изменил версию тензорного потока по умолчанию, и мой код возвращает следующую ошибку:

<ipython-input-3-b43b0e2085a4> in evaluate_norm_xls_net(seed, espandi_maschera)
 92     data = train_data, val_data, test_data
 93 
---> 94     history, models = training (train_data, val_data, test_data)
 95     return history, models, data
 96 

<ipython-input-3-b43b0e2085a4> in training(train_data, val_data, test_data)
  5     i = 0
  6     for param in paramss:
----> 7       net = Net(param)
  8       models[i] = net
  9       i+=1

/content/utils/masked_models_jac_xls.pyc in __init__(self, params)
 52 
 53         with tf.device(self.params.gpu):
---> 54             self.fc_mci = xalex3D (self.mri, self.jac, self.xls)
 55             self.output_mci = Dense(units = 1, activation = 'sigmoid', name = 'mci_output') (self.fc_mci)
 56 

/content/utils/masked_models_jac_xls.pyc in f(mri_volume, mri_volume_jacobian, clinical_inputs)
223 
224         #Introduce Middle Flow (separable convolutions with a residual connection)
--> 225         conv_mid_1 = mid_flow (conv2_concat, drop_rate, w_regularizer, filters = 96)
226 
227         #Split channels for grouped-style convolution

/content/utils/masked_models_jac_xls.pyc in mid_flow(x, drop_rate, w_regularizer, filters)
307     #3 consecutive separable blocks with a residual connection (refer to fig. 4)
308     residual = x
--> 309     x = _sepconv_bn_relu_pool_drop (filters, 3, 3, 3, padding='same', depth_multiplier = 1, drop_rate=drop_rate, w_regularizer = w_regularizer )(x)
310     x = _sepconv_bn_relu_pool_drop (filters, 3, 3, 3, padding='same', depth_multiplier = 1, drop_rate=drop_rate, w_regularizer = w_regularizer )(x)
311     x = _sepconv_bn_relu_pool_drop (filters, 3, 3, 3, padding='same', depth_multiplier = 1, drop_rate=drop_rate, w_regularizer = w_regularizer)(x)

/content/utils/masked_models_jac_xls.pyc in f(input)
295         sep_conv = SeparableConv3D(filters, (height, width, depth),
296                              strides = strides, depth_multiplier = depth_multiplier,kernel_initializer="he_normal",
--> 297                              padding=padding, kernel_regularizer = w_regularizer, name = name)(input)
298         sep_conv = BatchNormalization()(sep_conv)
299         elu = ELU()(sep_conv)

...
...
...

/tensorflow-1.15.2/python2.7/tensorflow_core/python/framework/ops.pyc in _disallow_in_graph_mode(self, task)
    521     raise errors.OperatorNotAllowedInGraphError(
    522         "{} is not allowed in Graph execution. Use Eager execution or decorate"
--> 523         " this function with @tf.function.".format(task))
    524 
    525   def _disallow_bool_casting(self):

OperatorNotAllowedInGraphError: using a `tf.Tensor` as a Python `bool` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.

Я думаю, после прочтения других тем в stackoverflow, что мне нужно изменить файл sepconv3D.py (который вы можете найти нажав на ссылку GitHub https://github.com/simeon-spasov/MCI/tree/master/utils), используя tf.cond () или @ tf.function (но я не знаю, как). Этот файл содержит настроенную версию отдельных сверток (в ней используется python 2.7)

Я попытался вернуться к предыдущей конфигурации colab с использованием% tenorflow_version 1.x, но это не решило проблему! Может быть, мне нужно изменить версию и других библиотек?

Ошибка в строке:

if self.bias:
            outputs = K.bias_add(
                    outputs,
                    self.bias,
                    data_format=self.data_format)

Кто-то может мне помочь?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...