1
下面是我使用的代碼:不能在CNTK蟒給eval圖像
import sys,os
import numpy as np
# import dicom
import glob
import cv2
import time
import cntk
import pandas as pd
from PIL import Image
from sklearn import cross_validation
from cntk import load_model
from cntk.ops import combine
from cntk.io import MinibatchSource, ImageDeserializer, StreamDef, StreamDefs
# from lightgbm.sklearn import LGBMRegressor
EXPERIMENT_NUMBER = '0042'
MODEL_PATH='C:/Projects/CNTK_data/Model/ResNet_152.model'
BATCH_SIZE=15
DATA_PATH='C:/Users/sharm_000/Desktop/Scraper/Images_Myntra/'
loaded_model=load_model(MODEL_PATH)
node_in_graph=loaded_model.find_all_with_name('z.x')
output_nodes = combine(node_in_graph)
import os
files=os.listdir(DATA_PATH)[0]
print files
>>> 0.jpg
fileswa=cv2.imread(DATA_PATH+files)
imgawa=cv2.resize(fileswa,(224,224))
rgb_image = np.asarray(imgawa, dtype=np.float32)
imgwa=np.ascontiguousarray(np.rollaxis(rgb_image, 2))
rgb_image.shape,imgwa.shape
>>>>((224L, 224L, 3L), (3L, 224L, 224L))
output_nodes.eval(imgwa)
ValueError異常:值:創建::的形狀的序列0([224 X 224])沒有被與樣品的形狀([3×224 X 224])兼容
請建議我缺少的是我所在的地方錯在這裏:
我也用:
imag1=cv2.imread(DATA_PATH+files)
imag2=cv2.resize(imag1,(224,224))
imag3=imag2.T
imag3=imag3.astype(int)
print imag2.shape,imag3.shape
>>>> (224L, 224L, 3L) (3L, 224L, 224L)
output_nodes.eval(imag3)
但相同的值誤差
問題解決最終代碼:
imag1=cv2.imread(DATA_PATH+files)
imag2=cv2.resize(imag1,(224,224))
imag3=imag2.T.astype(int)
imag4=np.ascontiguousarray(imag3)
print imag2.shape,imag3.shape
xxxx=output_nodes.eval({output_nodes.arguments[0]:[imag4]})
感謝伊馬德您的建議解決這個問題,它只是我需要添加一些更多的代碼得到它正確的,請你解釋一下,爲什麼它在密鑰對鍵入爲什麼不給圖像直接工作! –
得到了參考,Emad! https://www.cntk.ai/pythondocs/sequence.html#feeding-sequences-with-numpy –