读取张量流中的SVHN数据集

时间:2017-05-26 16:04:15

标签: python matlab tensorflow

我尝试在本教程中训练街景房号(SVHN)数据(Convolutional Neural Networks) 我用了

  

scipy.io.loadmat

但它不起作用,并给我这个错误::

  

TypeError:预期字符串,得到{'标题':b'MATLAB 5.0 MAT文件,平台:GLNXA64,创建时间:2011年12月5日21:09:26','版本':'1.0','全局':[],'X':数组([[[[[84,84,19,...,92,190, 216],            [30,76,54,......,78,188,217],            [38,59,110,...,101,191,212]],

    [[ 15,  86,  20, ...,  94, 205, 221],
     [ 23,  73,  52, ...,  82, 203, 222],
     [ 19,  66, 111, ..., 105, 206, 217]],

    [[ 15,  77,  25, ..., 114, 220, 226],
     [ 17,  78,  57, ..., 101, 218, 227],
     [ 19,  56, 116, ..., 125, 220, 221]],

    ..., 
    [[ 72,  90,  65, ..., 200, 229, 200],
     [ 65,  78, 144, ..., 201, 231, 199],
     [ 56,  69, 223, ..., 203, 224, 191]],

    [[ 82,  88,  78, ..., 192, 229, 193],
     [ 77,  77, 148, ..., 193, 229, 188],
     [ 57,  67, 218, ..., 195, 224, 182]],

    [[ 89,  88,  98, ..., 190, 229, 197],
     [ 79,  78, 158, ..., 191, 228, 189],
     [ 59,  66, 220, ..., 193, 223, 186]]],


   [[[ 28,  85,  21, ...,  92, 183, 204],
     [ 39,  77,  53, ...,  78, 182, 205],
     [ 35,  61, 110, ..., 103, 186, 202]],

    [[ 14,  83,  19, ...,  93, 200, 210],
     [ 25,  73,  52, ...,  80, 199, 211],
     [ 22,  64, 106, ..., 106, 201, 208]],

    [[ 14,  74,  25, ..., 111, 218, 220],
     [ 20,  69,  56, ...,  98, 217, 221],
     [ 17,  59, 111, ..., 124, 218, 217]],

    ..., 
    [[ 40,  89,  63, ..., 181, 227, 201],
     [ 39,  82, 137, ..., 180, 228, 199],
     [ 50,  64, 208, ..., 184, 223, 193]],

    [[ 67,  88,  91, ..., 177, 227, 195],
     [ 58,  79, 153, ..., 176, 226, 191],
     [ 52,  70, 214, ..., 180, 222, 186]],

    [[ 83,  88, 130, ..., 183, 228, 196],
     [ 78,  81, 180, ..., 182, 224, 190],
     [ 60,  67, 229, ..., 187, 221, 186]]],


   [[[ 40,  83,  21, ...,  99, 171, 198],
     [ 41,  76,  53, ...,  84, 170, 198],
     [ 38,  60, 110, ..., 112, 175, 197]],

    [[ 18,  78,  20, ...,  94, 189, 202],
     [ 21,  77,  51, ...,  81, 189, 202],
     [ 26,  58, 106, ..., 110, 193, 201]],

    [[ 16,  61,  22, ..., 107, 213, 212],
     [ 17,  50,  52, ...,  94, 213, 211],
     [ 23,  54, 106, ..., 123, 215, 210]],

    ..., 
    [[ 23,  90,  79, ..., 167, 231, 203],
     [ 29,  85, 147, ..., 166, 230, 200],
     [ 45,  63, 210, ..., 171, 226, 196]],

    [[ 35,  88, 125, ..., 172, 229, 198],
     [ 42,  83, 181, ..., 171, 226, 194],
     [ 44,  66, 230, ..., 176, 223, 191]],

    [[ 72,  85, 178, ..., 185, 227, 195],
     [ 69,  82, 218, ..., 184, 223, 190],
     [ 53,  70, 254, ..., 189, 220, 187]]],


   ..., 
   [[[ 86, 100,  88, ...,  99, 187, 233],
     [ 81,  98, 162, ...,  94, 185, 226],
     [ 75,  72, 237, ..., 110, 186, 228]],

    [[ 87,  98,  89, ...,  96, 204, 230],
     [ 82,  94, 163, ...,  91, 202, 224],
     [ 71,  76, 238, ..., 109, 199, 225]],

    [[ 82,  95,  84, ..., 108, 217, 228],
     [ 79,  93, 156, ..., 103, 217, 223],
     [ 65,  73, 230, ..., 124, 210, 221]],

    ..., 
    [[104, 104,  62, ..., 210, 204, 198],
     [104, 104, 142, ..., 207, 200, 196],
     [ 87,  86, 227, ..., 204, 195, 190]],

    [[104, 102,  67, ..., 206, 196, 184],
     [105, 102, 144, ..., 202, 193, 183],
     [ 81,  87, 226, ..., 200, 189, 177]],

    [[103, 100,  74, ..., 203, 196, 189],
     [105, 101, 145, ..., 197, 193, 187],
     [ 78,  78, 225, ..., 199, 189, 182]]],


   [[[ 84, 103,  88, ...,  94, 186, 231],
     [ 86, 104, 164, ...,  91, 184, 226],
     [ 64,  79, 240, ..., 103, 185, 228]],

    [[ 86, 106,  87, ...,  94, 198, 229],
     [ 79, 104, 160, ...,  91, 197, 224],
     [ 72,  79, 237, ..., 104, 194, 225]],

    [[ 82, 103,  88, ..., 110, 211, 227],
     [ 76, 103, 159, ..., 107, 211, 223],
     [ 72,  87, 237, ..., 121, 204, 222]],

    ..., 
    [[110, 103,  60, ..., 219, 222, 195],
     [103, 104, 141, ..., 218, 216, 194],
     [ 84,  86, 230, ..., 215, 212, 186]],

    [[106, 103,  61, ..., 218, 214, 181],
     [105, 103, 141, ..., 215, 209, 181],
     [ 85,  87, 228, ..., 212, 205, 173]],

    [[106, 105,  65, ..., 212, 208, 186],
     [104,  99, 143, ..., 209, 205, 183],
     [ 86,  81, 226, ..., 209, 200, 177]]],


   [[[ 85, 103,  84, ...,  88, 190, 230],
     [ 88, 106, 160, ...,  87, 188, 226],
     [ 68,  82, 238, ...,  94, 190, 227]],

    [[ 89, 103,  81, ...,  85, 199, 230],
     [ 82, 105, 154, ...,  84, 197, 226],
     [ 72,  87, 233, ...,  93, 194, 227]],

    [[ 85, 104,  87, ..., 105, 208, 229],
     [ 79, 106, 158, ..., 103, 208, 225],
     [ 67,  91, 238, ..., 114, 201, 226]],

    ..., 
    [[111, 113,  63, ..., 217, 232, 190],
     [104, 103, 144, ..., 217, 227, 190],
     [ 87,  88, 235, ..., 214, 223, 181]],

    [[109, 104,  62, ..., 221, 226, 178],
     [105, 104, 143, ..., 220, 221, 177],
     [ 86,  88, 232, ..., 219, 216, 169]],

    [[103, 103,  63, ..., 218, 218, 181],
     [106,  98, 145, ..., 217, 213, 178],
     [ 79,  80, 231, ..., 218, 209, 171]]]], dtype=uint8), 'y': array([[1],
   [9],
   [2],
   ..., 
   [1],
   [6],
   [9]], dtype=uint8)} of type 'dict' instead.

我无法理解问题,解决方案是什么。

1 个答案:

答案 0 :(得分:0)

该教程使用从文件中读取数据的方法,这种方法通常适用于数据集太大而无法保留在内存中的情况。本教程的这一部分有许多步骤,大部分都在cifar10_input.py中实现,它们通常遵循here步骤。

cifar10_input.py获取从中读取数据的文件名字符串列表。如果没有看到更多的代码,我猜这就是你遇到这个特定错误的原因。

您需要确保SVHN .mat文件具有正确的预期二进制格式(我怀疑是这种情况),然后在cifar10_input.py中为cifar10二进制文件交换该文件名,或者重写cifar10_train.py以使用占位符和feed_dict参数代替读取管道。请记住,需要将SVHN缩小到与cifar10_input.py中的cifar图像相同的大小。另外,对于feed_dict方法,SVHN数据集可能太大。