前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Java读取pkl文件_theano csv到pkl文件

Java读取pkl文件_theano csv到pkl文件

作者头像
全栈程序员站长
发布2022-09-30 12:35:31
1.3K0
发布2022-09-30 12:35:31
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

我正在尝试将一个pkl文件从csv起点加载到theano中

import numpy as np

import csv

import gzip, cPickle

from numpy import genfromtxt

import theano

import theano.tensor as T

#Open csv file and read in data

csvFile = “filename.csv”

my_data = genfromtxt(csvFile, delimiter=’,’, skip_header=1)

data_shape = “There are ” + repr(my_data.shape[0]) + ” samples of vector length ” + repr(my_data.shape[1])

num_rows = my_data.shape[0] # Number of data samples

num_cols = my_data.shape[1] # Length of Data Vector

total_size = (num_cols-1) * num_rows

data = np.arange(total_size)

data = data.reshape(num_rows, num_cols-1) # 2D Matrix of data points

data = data.astype(‘float32’)

label = np.arange(num_rows)

print label.shape

#label = label.reshape(num_rows, 1) # 2D Matrix of data points

label = label.astype(‘float32’)

print data.shape

#Read through data file, assume label is in last col

for i in range(my_data.shape[0]):

label[i] = my_data[i][num_cols-1]

for j in range(num_cols-1):

data[i][j] = my_data[i][j]

#Split data in terms of 70% train, 10% val, 20% test

train_num = int(num_rows * 0.7)

val_num = int(num_rows * 0.1)

test_num = int(num_rows * 0.2)

DataSetState = “This dataset has ” + repr(data.shape[0]) + ” samples of length ” + repr(data.shape[1]) + “. The number of training examples is ” + repr(train_num)

print DataSetState

train_set_x = data[:train_num]

train_set_y = label[:train_num]

val_set_x = data[train_num+1:train_num+val_num]

val_set_y = label[train_num+1:train_num+val_num]

test_set_x = data[train_num+val_num+1:]

test_set_y = label[train_num+val_num+1:]

# Divided dataset into 3 parts. split by percentage.

train_set = train_set_x, train_set_y

val_set = val_set_x, val_set_y

test_set = test_set_x, val_set_y

dataset = [train_set, val_set, test_set]

f = gzip.open(csvFile+’.pkl.gz’,’wb’)

cPickle.dump(dataset, f, protocol=2)

f.close()

当我通过Thenao(作为DBN或SdA)运行生成的pkl文件时,它预先训练得很好,这让我觉得数据存储正确 .

但是,当涉及到微调时,我收到以下错误:

epoch 1, minibatch 2775/2775, validation error 0.000000 %

Traceback (most recent call last):

File “SdA_custom.py”, line 489, in

test_SdA()

File “SdA_custom.py”, line 463, in test_SdA

test_losses = test_model()

File “SdA_custom.py”, line 321, in test_score

return [test_score_i(i) for i in xrange(n_test_batches)]

File “/usr/local/lib/python2.7/dist-packages/theano/compile/function_module.py”, line 606, in __call__

storage_map=self.fn.storage_map)

File “/usr/local/lib/python2.7/dist-packages/theano/compile/function_module.py”, line 595, in __call__

outputs = self.fn()

ValueError: Input dimension mis-match. (input[0].shape[0] = 10, input[1].shape[0] = 3)

Apply node that caused the error: Elemwise{neq,no_inplace}(argmax, Subtensor{int64:int64:}.0)

Inputs types: [TensorType(int64, vector), TensorType(int32, vector)]

Inputs shapes: [(10,), (3,)]

Inputs strides: [(8,), (4,)]

Inputs values: [‘not shown’, array([0, 0, 0], dtype=int32)]

Backtrace when the node is created:

File “/home/dean/Documents/DeepLearningRepo/DeepLearningTutorials-master/code/logistic_sgd.py”, line 164, in errors

return T.mean(T.neq(self.y_pred, y))

HINT: Use the Theano flag ‘exception_verbosity=high’ for a debugprint and storage map footprint of this apply node.

10是我的批次的大小,如果我改为批量大小为1,我得到以下内容:

ValueError: Input dimension mis-match. (input[0].shape[0] = 1, input[1].shape[0] = 0)

我认为我在制作pkl时错误地存储了标签,但我似乎无法发现正在发生的事情或为什么更改批处理会改变错误

希望你能帮忙!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年9月10日 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
文件存储
文件存储(Cloud File Storage,CFS)为您提供安全可靠、可扩展的共享文件存储服务。文件存储可与腾讯云服务器、容器服务、批量计算等服务搭配使用,为多个计算节点提供容量和性能可弹性扩展的高性能共享存储。腾讯云文件存储的管理界面简单、易使用,可实现对现有应用的无缝集成;按实际用量付费,为您节约成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档