AttributeError : 'tensorflow'모듈에는 tensorflow에 'get_default_graph'속성이 없습니다.
Aug 18 2020
내 코드에서 다음과 같은 오류가 발생합니다.
import mtcnn
# print version
print(mtcnn.__version__)
# demonstrate face detection on 5 Celebrity Faces Dataset
from os import listdir
from PIL import Image
from numpy import asarray
from matplotlib import pyplot
from mtcnn.mtcnn import MTCNN
print("MTCNN: {}".format(mtcnn.__version__))
import tensorflow as tf
from tensorflow import keras
# extract a single face from a given photograph
def extract_face(filename, required_size=(160, 160)):
# load image from file
image = Image.open(filename)
# convert to RGB, if needed
image = image.convert('RGB')
# convert to array
pixels = asarray(image)
# create the detector, using default weights
detector = MTCNN()
# detect faces in the image
results = detector.detect_faces(pixels)
# extract the bounding box from the first face
x1, y1, width, height = results[0]['box']
# bug fix
x1, y1 = abs(x1), abs(y1)
x2, y2 = x1 + width, y1 + height
# extract the face
face = pixels[y1:y2, x1:x2]
# resize pixels to the model size
image = Image.fromarray(face)
image = image.resize(required_size)
face_array = asarray(image)
return face_array
# specify folder to plot
#folder = '5-celebrity-faces-dataset/train/ben_afflek/'
folder = '5-celebrity-faces-dataset/train/ben_afflek'
i = 1
# enumerate files
for filename in listdir(folder):
# path
path = folder + '/' + filename
# get face
face = extract_face(path)
print(i, face.shape)
# plot
pyplot.subplot(2, 7, i)
pyplot.axis('off')
pyplot.imshow(face)
i += 1
pyplot.show()
오류:
anaconda3 \ envs \ py3 \ lib \ site-packages \ keras \ backend \ tensorflow_backend.py ", 68 행, get_uid 그래프 = tf.get_default_graph ()
AttributeError : 'tensorflow'모듈에 'get_default_graph'속성이 없습니다.
여러 가지 수입품을 시도했지만 아무것도 작동하지 않습니다. 이 오류는 일반적인 것 같지만 문제를 해결할 수있는 것이 없습니다.
답변
1 TimbusCalin Aug 18 2020 at 13:32
이 질문에 대해 여기에 당신이했던 것처럼 tensorflow에서 수입 keras, 문제를 해결한다.
그러나 귀하의 경우 문제는 MTCNN이 TensorFlow 대신 순수 Keras에서 작동하므로 tensorflow에서 "main.py"keras를로드해도 효과가 없다는 것입니다. tensorflow 버전을 다운 그레이드하거나 MTCNN의 모든 가져 오기를 수정해야합니다. 이는 안타깝게도 작동하지 않을 수 있습니다.