AttributeError: module ‘keras.backend‘ has no attribute ‘control_flow_ops‘

报错:

Using TensorFlow backend.
WARNING:tensorflow:From /tensorflow-1.15.2/python3.7/tensorflow_core/python/ops/resource_variable_ops.py:1630: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
2021-07-14 03:05:45.332302: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2021-07-14 03:05:45.358964: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-14 03:05:45.359533: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 0 with properties: 
name: Tesla T4 major: 7 minor: 5 memoryClockRate(GHz): 1.59
pciBusID: 0000:00:04.0
2021-07-14 03:05:45.359798: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2021-07-14 03:05:45.365019: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2021-07-14 03:05:45.366547: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2021-07-14 03:05:45.366868: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2021-07-14 03:05:45.374303: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2021-07-14 03:05:45.375449: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2021-07-14 03:05:45.379084: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2021-07-14 03:05:45.379185: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-14 03:05:45.379791: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-14 03:05:45.380304: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1767] Adding visible gpu devices: 0
2021-07-14 03:05:45.385000: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2199995000 Hz
2021-07-14 03:05:45.385171: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x556978f90d80 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-07-14 03:05:45.385198: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2021-07-14 03:05:45.576087: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-14 03:05:45.576817: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x556978f90f40 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2021-07-14 03:05:45.576847: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Tesla T4, Compute Capability 7.5
2021-07-14 03:05:45.577006: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-14 03:05:45.577562: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 0 with properties: 
name: Tesla T4 major: 7 minor: 5 memoryClockRate(GHz): 1.59
pciBusID: 0000:00:04.0
2021-07-14 03:05:45.577645: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2021-07-14 03:05:45.577668: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2021-07-14 03:05:45.577689: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2021-07-14 03:05:45.577708: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2021-07-14 03:05:45.577726: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2021-07-14 03:05:45.577745: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2021-07-14 03:05:45.577765: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2021-07-14 03:05:45.577834: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-14 03:05:45.578385: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-14 03:05:45.578901: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1767] Adding visible gpu devices: 0
2021-07-14 03:05:45.578962: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2021-07-14 03:05:45.579999: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1180] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-07-14 03:05:45.580028: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1186]      0 
2021-07-14 03:05:45.580039: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 0:   N 
2021-07-14 03:05:45.580144: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-14 03:05:45.580715: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-07-14 03:05:45.581230: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:39] Overriding allow_growth setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.
2021-07-14 03:05:45.581275: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1325] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 14257 MB memory) -> physical GPU (device: 0, name: Tesla T4, pci bus id: 0000:00:04.0, compute capability: 7.5)
Create YOLOv3 model with 9 anchors and 1 classes.
WARNING:tensorflow:From /tensorflow-1.15.2/python3.7/keras/backend/tensorflow_backend.py:3170: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0, which has the same broadcast rule as np.where
Traceback (most recent call last):
  File "/content/keras-yolo3/train.py", line 182, in <module>
    _main()
  File "/content/keras-yolo3/train.py", line 33, in _main
    freeze_body=2, weights_path='model_data/yolo_weights.h5') # make sure you know what you freeze
  File "/content/keras-yolo3/train.py", line 122, in create_model
    [*model_body.output, *y_true])
  File "/tensorflow-1.15.2/python3.7/keras/engine/base_layer.py", line 489, in __call__
    output = self.call(inputs, **kwargs)
  File "/tensorflow-1.15.2/python3.7/keras/layers/core.py", line 716, in call
    return self.function(inputs, **arguments)
  File "/content/keras-yolo3/yolo3/model.py", line 394, in yolo_loss
    _, ignore_mask = K.control_flow_ops.while_loop(lambda b,*args: b<m, loop_body, [0, ignore_mask])
AttributeError: module 'keras.backend' has no attribute 'control_flow_ops'

我用的google的colab版本,运行报错。原因是:keras版本太过于老。
处理办法:降低keras的版本
依次输入:

!pip uninstall keras-nightly

!pip install h5py==2.10.0

!pip uninstall keras

!pip inst`在这里插入代码片`all keras==2.2.4
class Solution {
public:
    vector<int> sortedSquares(vector<int>& nums) {
        vector<int> a;
        int p=0;
        for(int i = 0;i<nums.size();i++)
        {
            a.push_back(nums[i]*nums[i]);
            if(nums[i]<0&&nums[i+1]>=0){
                p = i+1;
            }
        }
        int i = 0;
        int j = nums.size()-1;
        while(i<p&&j>=p)
            { 
                if(a[i]>a[j])
                {
                    int t = a[i];
                    a[i] = a[j];
                    a[j] = t;
                    //cout<
                    cout<<a[i]<<" "<<a[i+1]<<endl;
                    if(a[i]>a[i+1])
                    { 
                        int m = a[i];
                        a[i] = a[i+1];
                        a[i+1] = m;
                    }
                    if(a[i]>a[p])
                    {
                        //cout<<"进来了"<
                        //cout<
    
                        int m = a[p];
                        a[p] = a[i];
                        a[i] = m;
                        //cout<
                    }
                
                    j--; 
                    i++;

                }
                else{
                    j--;
                }

            }
            return a;  

    }
};

你可能感兴趣的:(#,Python,#,机器学习,#,深度学习,keras,tensorflow,python)