前提・実現したいこと
pythonにおいてcifar10の32×32の画像データから0~255段階に分かれたヒストグラムのヒスト値のデータに変換してデータセットを作り直したいと思っています。
発生している問題・エラーメッセージ
txtファイルでデータセットを作りたいと思い、以下のコードを組み実行した後ファイルの中を見ると、ひとつの画像データにつき1行でデータを抑えたいのですが数行に渡ってのデータになってしまいました。
修正の仕方を教えていただきたいです。
エラーメッセージ
該当のソースコード
import numpy as np import dlt import cv2 # --------------------------------------------------------- data = dlt.cifar.load_cifar10() print(data.train_images.shape) print(data.train_labels.shape) print(data.test_images.shape) print(data.test_labels.shape) X_train = data.train_images.reshape([-1, 32, 32, 3]) X_test = data.test_images.reshape([-1, 32, 32, 3]) print('%i training samples' % X_train.shape[0]) print('%i test samples' % X_test.shape[0]) print(X_train.shape) Y_train = to_categorical(data.train_labels, 10) Y_test = to_categorical(data.test_labels, 10) nclasses = 50000 count = 0 for i in range(nclasses): X_train_gray = cv2.cvtColor(X_train[count],cv2.COLOR_RGB2GRAY) hist, bins = np.histogram(X_train[count].ravel(),256,[0,256]) #print(hist) with open('test1.txt','a') as file: print(hist, file=file) print(Y_train[count], file=file) print(count) count += 1
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/29 11:39
2018/05/29 11:43
2018/05/29 11:47