我正在使用 Google Colab 读取文件,但使用 Colab 时以下代码出错:
<块引用>类型错误:需要一个整数(得到类型 str)
# Import all the things we need ---
# by setting env variables before Keras import you can set up which backend and which GPU it uses
#import os
import numpy as np
from google.colab import drive
%matplotlib inline
from os import system, name
import os,random
os.environ["KERAS_BACKEND"] = "theano"
os.environ["KERAS_BACKEND"] = "tensorflow"
os.environ["THEANO_FLAGS"] = "device=gpu%d"%(1)
import numpy as np
#import theano as th
#import theano.tensor as T
from keras.utils import np_utils
import keras.models as models
from keras.layers.core import Reshape,Dense,Dropout,Activation,Flatten
from keras.layers.noise import GaussianNoise
from keras.layers.convolutional import Convolution2D, MaxPooling2D, ZeroPadding2D
from keras.regularizers import *
#from keras.optimizers import adam
from keras.optimizers import Adam
import matplotlib.pyplot as plt
import seaborn as sns
import pickle as cPickle
import random, sys, keras
drive.mount('/content/drive', force_remount=True)
PATH = "/content/drive/My Drive/Colab"
FILE_PATH = "/content/drive/My Drive/Colab"
MAIN_FILE_NAME = 'RML2016.10b.dat'
#data = np.loadtxt(os.path.join(FILE_PATH, MAIN_FILE_NAME), delimiter=',', usecols=(0, 1, 2, 3))
Xd = cPickle.load(open(FILE_PATH,MAIN_FILE_NAME,'rb'))
#Xd = cPickle.load(open("RML2016.10a_dict.dat",'rb'))
snrs,mods = map(lambda j: sorted(list(set(map(lambda x: x[j], Xd.keys())))), [1,0])
X = []
lbl = []
for mod in mods:
for snr in snrs:
X.append(Xd[(mod,snr)])
for i in range(Xd[(mod,snr)].shape[0]): lbl.append((mod,snr))
X = np.vstack(X)