ModuleNotFoundError:没有名为'caffe'的模块

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ModuleNotFoundError:没有名为'caffe'的模块相关的知识,希望对你有一定的参考价值。

我是python的新手...试图在Windows 10中的Python 3.6.8中运行一些代码当我执行以下代码时,我得到了ModuleNotFoundError:没有名为“ caffe”的模块错误

已安装

pip install caffe-ssd-x86

此后我遇到以下错误

Traceback (most recent call last):
  File "C:clean_water_ai-mastermycodecode.py", line 10, in <module>
    import caffe
  File "C:UsersElaAppDataLocalProgramsPythonPython36libsite-packagescaffe\__init__.py", line 1, in <module>
    from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
  File "C:UsersElaAppDataLocalProgramsPythonPython36libsite-packagescaffepycaffe.py", line 13, in <module>
    from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, 
ModuleNotFoundError: No module named 'caffe._caffe'

代码如下,分享您对解决此问题的意见

此代码是https://www.hackster.io/clean-water-ai/clean-water-ai-e40806#toc-step-4--collecting-data-for-ai-6中的净水AI代码应用程序的一部分>

import os
import glob
import random
import numpy as np
import cv2

import caffe
from caffe.proto import caffe_pb2
import lmdb
#Size of images
IMAGE_WIDTH = 227
IMAGE_HEIGHT = 227
def transform_img(img, img_width=IMAGE_WIDTH, img_height=IMAGE_HEIGHT):
   #Histogram Equalization
   img[:, :, 0] = cv2.equalizeHist(img[:, :, 0])
   img[:, :, 1] = cv2.equalizeHist(img[:, :, 1])
   img[:, :, 2] = cv2.equalizeHist(img[:, :, 2])
   #Image Resizing
   img = cv2.resize(img, (img_width, img_height), interpolation = cv2.INTER_CUBIC)
   return img
def make_datum(img, label):
   #image is numpy.ndarray format. BGR instead of RGB
   return caffe_pb2.Datum(
       channels=3,
       width=IMAGE_WIDTH,
       height=IMAGE_HEIGHT,
       label=label,
       data=np.rollaxis(img, 2).tostring())
train_lmdb = 'C:/clean_water_ai-master/mycode/face_training/input/train_lmdb'
validation_lmdb = 'C:/clean_water_ai-master/mycode/face_training/input/validation_lmdb'
os.system('rm -rf  ' + train_lmdb)
os.system('rm -rf  ' + validation_lmdb)
train_data = [img for img in glob.glob("../input/train/*jpg")]
test_data = [img for img in glob.glob("../input/test1/*jpg")]
#Shuffle train_data
random.shuffle(train_data)
print ('Creating train_lmdb')
in_db = lmdb.open(train_lmdb, map_size=int(1e12))
with in_db.begin(write=True) as in_txn:
   for in_idx, img_path in enumerate(train_data):
       if in_idx %  6 == 0:
           continue
       img = cv2.imread(img_path, cv2.IMREAD_COLOR)
       img = transform_img(img, img_width=IMAGE_WIDTH, img_height=IMAGE_HEIGHT)
       if 'yeast' in img_path:
           label = 0
       else:
           label = 1
       datum = make_datum(img, label)
       in_txn.put('{:0>5d}'.format(in_idx), datum.SerializeToString())
       print ('{:0>5d}'.format(in_idx) + ':' + img_path)
in_db.close()
print ('
Creating validation_lmdb')
in_db = lmdb.open(validation_lmdb, map_size=int(1e12))
with in_db.begin(write=True) as in_txn:
   for in_idx, img_path in enumerate(train_data):
       if in_idx % 6 != 0:
           continue
       img = cv2.imread(img_path, cv2.IMREAD_COLOR)
       img = transform_img(img, img_width=IMAGE_WIDTH, img_height=IMAGE_HEIGHT)
       if 'yeast' in img_path:
           label = 0
       else:
           label = 1
       datum = make_datum(img, label)
       in_txn.put('{:0>5d}'.format(in_idx), datum.SerializeToString())
       print ('{:0>5d}'.format(in_idx) + ':' + img_path)
in_db.close()
print ('
Finished processing all images')

我是python的新手...试图在Windows 10中的Python 3.6.8中运行某些代码,我执行以下代码,我得到了ModuleNotFoundError:没有名为'caffe'的模块错误,所以安装了pip install ...] >

答案

caffe模块不是Python标准发行版的一部分。您需要单独安装。大多数时候,您应该可以通过在终端中运行pip install caffe来执行此操作。希望对您有所帮助!

以上是关于ModuleNotFoundError:没有名为'caffe'的模块的主要内容,如果未能解决你的问题,请参考以下文章

ModuleNotFoundError:没有名为“dataviz”的模块

ModuleNotFoundError:没有名为“numpy”的模块

错误:ModuleNotFoundError:没有名为“图像”的模块

ModuleNotFoundError:没有名为“knox”的模块

ModuleNotFoundError:没有名为“memoize”的模块

ModuleNotFoundError:没有名为“pssh”的模块