以下是我正在使用的代码:
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:Value :: Create ::序列0的形状([224 x 224])与样本形状不兼容([3 x 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]})
答案 0 :(得分:3)
你可以尝试:
output_nodes.eval({output_nodes.arguments[0]:[imag3]}))
答案 1 :(得分:0)
看起来您的图片是单个频道,而不是3个彩色图片频道。你可以请将你的图像阵列重塑为(1,224,224)维度。假设您的模型也期望单个通道。如果模型需要3个通道,则可以复制阵列并创建具有3个通道的伪灰度图像。