解决python在import caffe时出现的no module name _caffe问题
来源:互联网 发布:广电网络梅江电话 编辑:程序博客网 时间:2024/06/18 10:57
在python文件的最上面放上下面内容就可以了
import sys
sys.path.append("/home/zhangqi/Desktop/caffe-master/python")
sys.path.append("/home/zhangqi/Desktop/caffe-master/python/caffe")
#############################################################################################
记得修改caffe_forward.py文件的路径
import syssys.path.append("/home/zhangqi/Desktop/caffe-master/python")sys.path.append("/home/zhangqi/Desktop/caffe-master/python/caffe")import caffeimport cv2 as cvimport matplotlib.pyplot as pltimport numpy as npmodel_defination = '/usr/xhh/model/general_prediction/cnn/forward_network.prototxt'weights = '/usr/xhh/model/general_prediction/cnn/train_iter_146000.caffemodel'data_path='/usr/xhh/model/general_prediction/cnn/current_position.txt'def load_net(list): caffe.set_mode_cpu() # net=caffe.Net(weights) net=caffe.Net(model_defination,weights,caffe.TEST) transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape}) # transformer.set_transpose('data', (2, 0, 1)) # transformer.set_mean('data', ()) # Load the mean file # transformer.set_raw_scale('data', 1) # transformer.set_channel_swap('data', (2, 1, 0)) # Convert RGB to GBR net.blobs['data'].reshape(1, 3, 19, 19) data=get_img_datum(data_path) # net.blobs['data'].data[...] = transformer.preprocess('data', data) net.blobs['data'].data[...] = data.reshape(1, 3, 19, 19) res = net.forward() res = np.asarray(res['loss']) res=res[0] if list[0]!='': for i in list: res[int(i)]=0 res=res.tolist() a=sorted(res,reverse=True) index=res.index(a[0]) #res = res.reshape((19, 19)) #plt.imshow(res, cmap= plt.cm.jet) print index for i in range(50): print res.index(a[i])def get_img_datum(data_path): file=open(data_path) for line in file: str=line.split() img=np.zeros((3,19,19)) img1=np.zeros((19,19)) img2=np.zeros((19,19)) img3=np.zeros((19,19)) i=0 j=0 for s1 in str[0]: img1[i,j]=int(s1) i=i+1 if i>18: i=0 j=j+1 i=0 j=0 for s2 in str[1]: img2[i,j]=int(s2) i=i+1 if i>18: i=0 j=j+1 i=0 j=0 for s3 in str[2]: img3[i,j]=int(s3) i=i+1 if i>18: i=0 j=j+1 img[0,:,:]=img1 img[1,:,:]=img2 img[2,:,:]=img3 return imgif __name__ == '__main__': index="" list=[] jList=sys.argv[1:] jList_str="" for i in jList: jList_str+=i jList_str=jList_str[1:len(jList_str)-1] list=jList_str.split(',') load_net(list)
0 0
- 解决python在import caffe时出现的no module name _caffe问题
- import caffe失败 No module named caffe 或 ImportError:No module named _caffe
- 解决Python import “No module named ”问题
- No module named _caffe 和No module named caffe错误解决
- 在python中提示ImportError: No module named _caffe
- python import no module错误解决
- 解决java调用python的Cannot import site module and its dependencies: No module named site问题
- Compilation with Make in Caffe.ImportError: No module named _caffe
- python导入caffe时出现python caffe报错:No module named google.protobuf.internal
- import caffe失败 No module named caffe
- import caffe ImportError: No module named caffe
- import caffe失败 No module named caffe
- import caffe失败 No module named caffe
- No module named cv2 和 import caffe失败问题的解决方法
- 解决caffe debug 1-Pycharm import caffe 报错 no module named caffe
- Python 导入模块import MySQLdb 出现:No module named MySQLdb
- 在ipython notebook 上测试 ImportError: No module named _caffe
- 在caffe.proto中定义变量出现“'xxxParameter' has no member named 'xxx'”问题的解决
- poj入门水题整理13
- 链表的有序集合(Set用法)
- jsontest
- Android的别踩白块开发,使用SurfaceView(二)
- 二叉树的所有路径
- 解决python在import caffe时出现的no module name _caffe问题
- 二叉树的中序遍历
- JaveMail实现发送QQ邮件
- 厨娘的Java笔记(一):强制类型转换之引用转换
- 【实战】Python读写Excel实例应用
- 三种寻找最长递增(减)子序列的方法【LIS】
- 队列的两种实现方式
- STL中的数据结构笔记(一)
- ZOJ-Hard to Play