只是好奇,使用 GOOGLE COLAB TPU 在 IMAGENET 上训练 VGG16 模型需要多长时间?如果有人能向我解释他们为得到答案所做的计算,那就太好了!
deep-learning tensorflow google-colaboratory google-cloud-tpu tpu
我正在尝试访问google colaboratory 中的spacenet 挑战数据集(https://registry.opendata.aws/spacenet/)。如何在 google colaboratory 中获取它?
python amazon-s3 amazon-web-services deep-learning google-colaboratory
我有两个具有相同参数的相同模型。这两个都是在 MNIST 数据集上训练的。第一个使用 model.fit() 训练,第二个使用 model.train_on_batch() 训练。第二种模型的准确性较低。我想知道可能是什么原因以及如何解决它?
数据准备:
batch_size = 150
num_classes = 10
epochs = 12
# input image dimensions
img_rows, img_cols = 28, 28
# the data, split between train and test sets
(x_train, y_train), (x_test, y_test) = mnist.load_data()
if K.image_data_format() == 'channels_first':
x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols)
x_test = x_test.reshape(x_test.shape[0], 1, img_rows, img_cols)
input_shape = (1, img_rows, img_cols)
else:
x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)
x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)
input_shape = (img_rows, img_cols, 1) …Run Code Online (Sandbox Code Playgroud) 我在 Google colab 中训练了我的模型,然后使用model1.save('thebestonesofar57block5.h5'). 之后我将文件下载到我的 Windows 机器上。将其上传到新的 google colab 会话后,我收到以下错误,使用:
from keras.models import load_model
Loaded_model = load_model('thebestonesofar57block5.h5')
Run Code Online (Sandbox Code Playgroud)
错误:
OSError:无法打开文件(截断的文件:eof = 7340032,sblock->base_addr = 0,stored_eof = 126651688)
我将相同的输入(即相同的数据和相同的真实标签)传递给 keras train_on_batch() 和 test_on_batch()。我想知道为什么我的两个函数得到不同的损失值。
代码:
model_del_fin.compile(optimizer=SGD(lr=0.001,decay=0.001/15), loss='categorical_crossentropy',metrics=['accuracy'])
iters_per_epoch = 1285 // 50
print(iters_per_epoch)
num_epochs = 15
outs_store_freq = 20 # in iters
print_loss_freq = 20 # in iters
iter_num = 0
epoch_num = 0
model_outputs = []
loss_history = []
while epoch_num < num_epochs:
print("ok")
while iter_num < iters_per_epoch:
x_train, y_train = next(train_it2)
loss_history += [model_del_fin.train_on_batch([x_train,x_train], y_train)]
print("Iter {} loss: {}".format(iter_num, loss_history[-1]))
print(model_del_fin.test_on_batch([x_train,x_train], y_train))
iter_num += 1
print("EPOCH {} FINISHED".format(epoch_num + 1))
epoch_num += 1
iter_num = 0 # …Run Code Online (Sandbox Code Playgroud) 我有一个非常大的形状张量(512,3,224,224)。我将其以 32 个批次输入到模型中,然后保存与目标标签相对应的分数2。在每次迭代中,在每个切片之后,形状都会发生scores变化。这会导致以下错误。我做错了什么以及如何解决它。
label = torch.ones(1)*2
def sub_forward(self, x):
x = self.vgg16(x)
x = self.bn1(x)
x = self.linear1(x)
x = self.linear2(x)
return x
Run Code Online (Sandbox Code Playgroud)
def get_scores(self, imgs, targets):
b, _, _, _ = imgs.shape
batch_size = 32
total_scores = []
for i in range(0, b, batch_size):
scores = self.sub_forward(imgs[i:i+batch_size,:,:,:])
scores = F.softmax(scores)
labels = targets[i:i+batch_size]
labels = labels.long()
scores = scores[:,labels]
print(i," scores: ", scores)
total_scores.append(scores)
print(i," total_socres: ", total_scores)
total_scores = torch.stack(total_scores)
return scores …Run Code Online (Sandbox Code Playgroud)