前提・実現したいこと
こちらのサイトに掲載されているSegNetのプログラムを拝借して実行したところ、datasetプログラムで下記のようなエラーが発生するようになってしまいました。
これはTensorFlowがインポートできていないということなのでしょうか?原因がわからないので、解決策を教えていただきたいです。
発生している問題・エラーメッセージ
runfile('C:/Users/ユーザ名/.spyder-py3/dataset.py', wdir='C:/Users/t.k/.spyder-py3') Using TensorFlow backend. Traceback (most recent call last): File "<ipython-input-6-ef8e060fac88>", line 1, in <module> runfile('C:/Users/ユーザ名/.spyder-py3/dataset.py', wdir='C:/Users/t.k/.spyder-py3') File "C:\Users\ユーザ名\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile execfile(filename, namespace) File "C:\Users\ユーザ名\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "C:/Users/ユーザ名/.spyder-py3/dataset.py", line 11, in <module> from keras.applications import imagenet_utils File "C:\Users\ユーザ名\Anaconda3\lib\site-packages\keras\__init__.py", line 3, in <module> from . import utils File "C:\Users\ユーザ名\Anaconda3\lib\site-packages\keras\utils\__init__.py", line 6, in <module> from . import conv_utils File "C:\Users\ユーザ名\Anaconda3\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module> from .. import backend as K File "C:\Users\ユーザ名\Anaconda3\lib\site-packages\keras\backend\__init__.py", line 89, in <module> from .tensorflow_backend import * File "C:\Users\ユーザ名\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module> import tensorflow as tf File "C:\Users\ユーザ名\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 24, in <module> from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import File "C:\Users\ユーザ名\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module> from tensorflow.python import pywrap_tensorflow File "C:\Users\ユーザ名\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module> raise ImportError(msg) ImportError: Traceback (most recent call last): File "C:\Users\ユーザ名\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module> from tensorflow.python.pywrap_tensorflow_internal import * File "C:\Users\ユーザ名\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module> _pywrap_tensorflow_internal = swig_import_helper() File "C:\Users\ユーザ名\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "C:\Users\ユーザ名\Anaconda3\lib\imp.py", line 243, in load_module return load_dynamic(name, filename, file) File "C:\Users\ユーザ名\Anaconda3\lib\imp.py", line 343, in load_dynamic return _load(spec) ImportError: DLL load failed: 指定されたモジュールが見つかりません。 Failed to load the native TensorFlow runtime. See https://www.tensorflow.org/install/install_sources#common_installation_problems for some common reasons and solutions. Include the entire stack trace above this error message when asking for help.
該当のソースコード
# -*- coding: utf-8 -*- import cv2 import numpy as np from keras.applications import imagenet_utils import os DataPath = './CamVid/' data_shape = 360*480 class Dataset: def __init__(self, classes=12, train_file='train.txt', test_file='test.txt'): self.train_file = train_file self.test_file = test_file self.data_shape = 360*480 self.classes = classes def normalized(self, rgb): #return rgb/255.0 norm=np.zeros((rgb.shape[0], rgb.shape[1], 3),np.float32) b=rgb[:,:,0] g=rgb[:,:,1] r=rgb[:,:,2] norm[:,:,0]=cv2.equalizeHist(b) norm[:,:,1]=cv2.equalizeHist(g) norm[:,:,2]=cv2.equalizeHist(r) return norm def one_hot_it(self, labels): x = np.zeros([360,480,12]) for i in range(360): for j in range(480): x[i,j,labels[i][j]] = 1 return x def load_data(self, mode='train'): data = [] label = [] if (mode == 'train'): filename = self.train_file else: filename = self.test_file with open(DataPath + filename) as f: txt = f.readlines() txt = [line.split(' ') for line in txt] for i in range(len(txt)): data.append(self.normalized(cv2.imread(os.getcwd() + txt[i][0][7:]))) label.append(self.one_hot_it(cv2.imread(os.getcwd() + txt[i][1][7:][:-1])[:,:,0])) print('.',end='') #print("train data file", os.getcwd() + txt[i][0][7:]) #print("label data raw", cv2.imread(os.getcwd() + '/CamVid/trainannot/0001TP_006690.png')) return np.array(data), np.array(label) def preprocess_inputs(self, X): ### @ https://github.com/fchollet/keras/blob/master/keras/applications/imagenet_utils.py """Preprocesses a tensor encoding a batch of images. # Arguments x: input Numpy tensor, 4D. data_format: data format of the image tensor. mode: One of "caffe", "tf". - caffe: will convert the images from RGB to BGR, then will zero-center each color channel with respect to the ImageNet dataset, without scaling. - tf: will scale pixels between -1 and 1, sample-wise. # Returns Preprocessed tensor. """ return imagenet_utils.preprocess_input(X) def reshape_labels(self, y): return np.reshape(y, (len(y), self.data_shape, self.classes))
試したこと
KerasやTensorFlow関係のパッケージはインストールしてあります。
(パッケージのインストールは、Anaconda Navigator 上で行いました。)
補足情報(FW/ツールのバージョンなど)
開発環境
- Windows7 (64bit)
- Spyder (Python3.6)
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。