本文整理汇总了Python中mnist.MNIST.display方法的典型用法代码示例。如果您正苦于以下问题:Python MNIST.display方法的具体用法?Python MNIST.display怎么用?Python MNIST.display使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mnist.MNIST
的用法示例。
在下文中一共展示了MNIST.display方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: query_digit
# 需要导入模块: from mnist import MNIST [as 别名]
# 或者: from mnist.MNIST import display [as 别名]
def query_digit(digit):
host, port = "localhost", 4567
con = httplib.HTTPConnection(host, port)
params = json.dumps({"data": digit})
con.request("POST", "/digit", params)
response = con.getresponse()
print "For digit:%s\nReceived prediction response [%s]\n" % (MNIST.display(digit), response.read())
示例2: query_digit
# 需要导入模块: from mnist import MNIST [as 别名]
# 或者: from mnist.MNIST import display [as 别名]
def query_digit(digit, host=None, port=None):
"""
Issues HTTP POST to host, port with digit array
Expects a digit in the response
"""
if not host or not port:
host, port = "localhost", 4567
con = httplib.HTTPConnection(host, port)
params = json.dumps({"data": digit})
con.request("POST", "/digit", params)
response = con.getresponse()
print "For digit:%s\nReceived prediction response [%s]\n" % (MNIST.display(digit), response.read())
示例3: MNIST
# 需要导入模块: from mnist import MNIST [as 别名]
# 或者: from mnist.MNIST import display [as 别名]
from mnist import MNIST
#you can find python-mnist source code on https://github.com/sorki/python-mnist
datahandler = MNIST() #change for data path
train_data = datahandler.load_training()
for i in range(59989, 60000):
print('IMAGE: {}'.format(i+1))
img = train_data[0][i]
print(datahandler.display(img))
print('LABEL: {}\n\n\n'.format(train_data[1][i]))
示例4: draw_random_misclassification
# 需要导入模块: from mnist import MNIST [as 别名]
# 或者: from mnist.MNIST import display [as 别名]
def draw_random_misclassification(truth_array, prediction, test_label, test_data):
"""
Prints the prediction, label and digit for a random misclassified sample
"""
incorrect_idx = [idx for idx, is_true in enumerate(truth_array) if not is_true]
n = incorrect_idx[np.random.randint(0, len(incorrect_idx))]
print "predicted [%s]\nlabeled [%s]\nraw data:\n%s" % (prediction[n].argmax(), test_label[n], MNIST.display(test_data[n]))
示例5: print
# 需要导入模块: from mnist import MNIST [as 别名]
# 或者: from mnist.MNIST import display [as 别名]
if TF_MNIST_IMAGE_PATH != None:
raw_image = Image.open(TF_MNIST_IMAGE_PATH)
int_image = numpy.array(raw_image)
image = numpy.reshape(int_image, 784).astype(numpy.float32)
elif TF_MNIST_TEST_IMAGE_NUMBER > -1:
test_data_set = input_data.read_data_sets(TF_DATA_DIR, one_hot=True).test
image = test_data_set.images[TF_MNIST_TEST_IMAGE_NUMBER]
else:
test_data_set = input_data.read_data_sets(TF_DATA_DIR, one_hot=True).test
image = random.choice(test_data_set.images)
channel = implementations.insecure_channel(
TF_MODEL_SERVER_HOST, TF_MODEL_SERVER_PORT)
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
request = predict_pb2.PredictRequest()
request.model_spec.name = "mnist"
request.model_spec.signature_name = "predict_images"
request.inputs['images'].CopyFrom(
tf.contrib.util.make_tensor_proto(image, shape=[1, 784]))
result = stub.Predict(request, 10.0) # 10 secs timeout
# print(result)
print(MNIST.display(image, threshold=0))
response = numpy.array(
result.outputs['scores'].float_val)
prediction = numpy.argmax(response)
# print(prediction)
print("Your model says the above number is... %d!" %
prediction)