谷歌构建tensorflow教程时出错

时间:2019-04-20 03:08:27

标签: tensorflow tensorflow2.0

我是tensorflow的新手。我无法构建tensorflow 2.0的google tensorflow教程。这是页面https://www.tensorflow.org/alpha/tutorials/keras/basic_classification 我无法从Google下载数据。因此,我将数据下载到本地,并使用mnist_reader读取数据。然后我检查了mnist_reader的输出,图像大小正确(28 * 28)。

filterSelection("all")
function filterSelection(c) {
  var x, i;
  x = document.getElementsByClassName("column");
  if (c == "all") c = "";
  for (i = 0; i < x.length; i++) {
    w3RemoveClass(x[i], "show");
    if (x[i].className.indexOf(c) > -1) w3AddClass(x[i], "show");
  }
}

function w3AddClass(element, name) {
  var i, arr1, arr2;
  arr1 = element.className.split(" ");
  arr2 = name.split(" ");
  for (i = 0; i < arr2.length; i++) {
    if (arr1.indexOf(arr2[i]) == -1) {element.className += " " + arr2[i];}
  }
}

function w3RemoveClass(element, name) {
  var i, arr1, arr2;
  arr1 = element.className.split(" ");
  arr2 = name.split(" ");
  for (i = 0; i < arr2.length; i++) {
    while (arr1.indexOf(arr2[i]) > -1) {
      arr1.splice(arr1.indexOf(arr2[i]), 1);     
    }
  }
  element.className = arr1.join(" ");
}

// Add active class to the current button (highlight it)
var btnContainer = document.getElementById("myBtnContainer");
var btns = btnContainer.getElementsByClassName("button");
for (var i = 0; i < btns.length; i++) {
  btns[i].addEventListener("click", function(){
    var current = document.getElementsByClassName("is-active");
    current[0].className = current[0].className.replace(" is-active", "");
    this.className += " is-active";
  });
}

关于model.fit有一个例外。

def load_mnist(path, kind='train'):
import os
import gzip
import numpy as np

"""Load MNIST data from `path`"""
labels_path = os.path.join(path,
                           '%s-labels-idx1-ubyte.gz'
                           % kind)
images_path = os.path.join(path,
                           '%s-images-idx3-ubyte.gz'
                           % kind)

with gzip.open(labels_path, 'rb') as lbpath:
    labels = np.frombuffer(lbpath.read(), dtype=np.uint8,
                           offset=8)

with gzip.open(images_path, 'rb') as imgpath:
    images = np.frombuffer(imgpath.read(), dtype=np.uint8,
                           offset=16).reshape(len(labels), 28, 28)

return images, labels

0 个答案:

没有答案