我使用来自Keras的ResNet50的转移学习训练了一个宪法网络,如下所示.
base_model = applications.ResNet50(weights='imagenet', include_top=False, input_shape=(333, 333, 3))
## set model architechture
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(1024, activation='relu')(x)
x = Dense(256, activation='relu')(x)
predictions = Dense(y_train.shape[1], activation='softmax')(x)
model = Model(input=base_model.input, output=predictions)
model.compile(loss='categorical_crossentropy', optimizer=optimizers.SGD(lr=1e-4, momentum=0.9),
metrics=['accuracy'])
model.summary()
Run Code Online (Sandbox Code Playgroud)
在训练模型后,我想保存模型.
history = model.fit_generator(
train_datagen.flow(x_train, y_train, batch_size=batch_size),
steps_per_epoch=600,
epochs=epochs,
callbacks=callbacks_list
)
Run Code Online (Sandbox Code Playgroud)
我不能使用keras模型中的save_model()函数,因为模型在这里是Model类型.我使用save()函数来保存模型.但后来当我加载模型并验证模型时,它表现得像一个未经训练的模型.我认为重量没有得到保存.哪里错了.?如何正确保存此模型.
我正在使用此代码在我的android应用程序中显示通知。这在所有android版本中都可以正常工作,但是在Android 9中没有任何通知显示。
我试图用不同的方法来实现这一点,但没有任何效果。
public void showNotification(String heading, String description, String imageUrl, Intent intent){
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
createChannel();
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,"channelID")
.setSmallIcon(R.drawable.logo)
.setContentTitle(heading)
.setContentText(description)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int notificationId = (int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE);
notificationManager.notify(notificationId, notificationBuilder.build());
}
public void createChannel(){
if (Build.VERSION.SDK_INT < 26) {
return;
}
NotificationManager notificationManager =
(NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = new NotificationChannel("channelID","name", NotificationManager.IMPORTANCE_DEFAULT); …Run Code Online (Sandbox Code Playgroud) 我策划了catplot在seaborn这样的
import seaborn as sns
import pandas as pd
data = {'year': [2016, 2013, 2014, 2015, 2016, 2013, 2014, 2015, 2016, 2013, 2014, 2015, 2016, 2013, 2014, 2015, 2016, 2013, 2014, 2015], 'geo_name': ['Michigan', 'Michigan', 'Michigan', 'Michigan', 'Washtenaw County, MI', 'Washtenaw County, MI', 'Washtenaw County, MI', 'Washtenaw County, MI', 'Ann Arbor, MI', 'Ann Arbor, MI', 'Ann Arbor, MI', 'Ann Arbor, MI', 'Philadelphia, PA', 'Philadelphia, PA', 'Philadelphia, PA', 'Philadelphia, PA', 'Ann Arbor, MI Metro Area', 'Ann Arbor, …Run Code Online (Sandbox Code Playgroud) 我通过在 Keras 中使用 ImageDataGenerator 训练了一个应用一些图像增强的模型,如下所示:
train_datagen = ImageDataGenerator(
rotation_range=60,
width_shift_range=0.1,
height_shift_range=0.1,
horizontal_flip=True)
train_datagen.fit(x_train)
history = model.fit_generator(
train_datagen.flow(x_train, y_train, batch_size=7),
steps_per_epoch=600,
epochs=epochs,
callbacks=callbacks_list
)
Run Code Online (Sandbox Code Playgroud)
我应该如何使用此模型进行预测?通过使用model.predict()如下所示?
predictions = model.predict(x_test)
Run Code Online (Sandbox Code Playgroud)
或者我应该在未标记的model.predict_generator()地方使用 ImageDataGenerator 的x_test地方x_test?
如果我使用predict_generator():怎么做?
两种方法有什么区别?
我在keras中实现自定义损失功能。该模型是autoencoder。所述第一层是一个嵌入层,其嵌入尺寸的输入(batch_size, sentence_length)到(batch_size, sentence_length, embedding_dimension)。然后,模型将嵌入压缩为一定维数的向量,最后必须重建嵌入(batch_size, sentence_lenght, embedding_dimension)。
但是嵌入层是可训练的,并且损失必须使用嵌入层的权重(我必须对词汇表的所有词嵌入进行求和)。
例如,如果我想训练玩具示例:“猫”。的sentence_length is 2并假设embedding_dimension is 10和vocabulary size is 50,所以嵌入矩阵具有形状(50,10)。嵌入层的输出X为shape (1,2,10)。然后,它传递到模型中,并且输出X_hat也具有形状(1,2,10)。必须对模型进行训练,以最大程度地提高在嵌入层中表示“ the” X_hat[0]的矢量与X[0]表示“ the” 的矢量最相似的可能性,而对于“ cat”也一样。但是损失是如此之大,以至于我必须计算X和之间的余弦相似度,并X_hat通过将的余弦相似度之和归一化X_hat 以及嵌入矩阵中的每个嵌入(由于词汇量为50,因此为50),它们是嵌入层权重的列。
但是,在训练过程的每次迭代中,如何访问嵌入层中的权重?
谢谢 !
我在 Android 上以 YUV_420_888 格式 (YCbCr) 捕获图像。
图像尺寸为4032 X 3024,我从ImageReader获得三个平面。
Y 具有 12192768 字节
U 具有 6096383 字节
V 具有 6096383 字节
我的理解是,Y中的每个像素在U/V平面上都有一个对应的值,比例为 2:1(2 个像素 Y 对应一个像素 U/V)。
但计算一下12192768/2,U/V平面中缺少一个字节。
为什么少了一个字节?Android相机2 YUV_420_888的Y和U/V之间的关系如何。
我在 pyspark 中有一个 Spark ML 管道,如下所示,
scaler = StandardScaler(inputCol="features", outputCol="scaled_features")
pca = PCA(inputCol=scaler.getOutputCol(), outputCol="pca_output")
kmeans = clustering.KMeans(seed=2014)
pipeline = Pipeline(stages=[scaler, pca, kmeans])
Run Code Online (Sandbox Code Playgroud)
训练模型后,我想获得每个样本的轮廓系数,就像sklearn中的这个函数一样
我知道我可以使用 ClusteringEvaluator 并为整个数据集生成分数。但我想对每个样本都这样做。
如何在 pyspark 中有效地实现这一目标?
我经历过的github的一些代码,发现了一个名为层ConvLSTM2D在Keras。该Keras单证规定It is similar to an LSTM layer, but the input transformations and recurrent transformations are both convolutional.。
我想知道这一层的实际应用是什么。我对NLP很熟悉,我还没有看到使用这一层。
机器学习/深度学习的哪个领域使用了这一层。?
我有一个 Pandas 时间戳列表。它应该是分开的 15 分钟,但由于测量中的一些错误,可能会在几分钟内出现错误。
我想将时间戳四舍五入到下一个最接近的 15 分钟。
我知道我可以使用Timestamp.round()from pandas 来舍入时间戳。但问题是它四舍五入到最接近的 15 分钟。我总是想四舍五入到接下来的 15 分钟。
例如,
如果我有下面给出的时间戳,
ts = pd.Timestamp('2017-12-31 23:50:00+0530')
rounded = ts.round(freq='15T')
Run Code Online (Sandbox Code Playgroud)
我将得到的结果是Timestamp('2017-12-31 23:45:00+0530', tz='pytz.FixedOffset(330)')。
我不希望这种情况发生,我希望结果是下一个 15 分钟的时间戳,即它必须是
Timestamp('2018-01-01 00:00:00+0530', tz='pytz.FixedOffset(330)')
Run Code Online (Sandbox Code Playgroud)
同时,我将有表单的时间戳
Timestamp('2018-01-01 00:00:00+0530', tz='pytz.FixedOffset(330)')
Run Code Online (Sandbox Code Playgroud)
如果我Timestamp.ceil用于我的目的,我会得到这样的输出
Timestamp('2018-01-01 00:15:00+0530', tz='pytz.FixedOffset(330)')
Run Code Online (Sandbox Code Playgroud)
我不希望它发生。
输出必须是
Timestamp('2018-01-01 00:00:00+0530', tz='pytz.FixedOffset(330)')
Run Code Online (Sandbox Code Playgroud)
简而言之,如果时间戳是正确的,则不必进行 cieling,如果时间戳不是 15 分钟,则必须对其进行 ceiling。
我怎样才能轻松地用熊猫做到这一点。?
我有一个这样的python dict,
d = {
"k1" : "v1",
"k2" : "v2"
}
Run Code Online (Sandbox Code Playgroud)
我想从 dict 中获取 k1 的值,我可以这样做,
d.get("k1")
Run Code Online (Sandbox Code Playgroud)
但问题是,有时 k1 会出现在 dict 中。在这种情况下,我想从字典中选择 k2。我现在就这样做
val = d.get("k1", None)
if not val:
val = d.get("k2", None)
Run Code Online (Sandbox Code Playgroud)
我也可以这样做
if "k1" in d:
val = d['k1']
else:
val = d.get("k2", None)
Run Code Online (Sandbox Code Playgroud)
这些解决方案看起来不错并且按预期工作,我想知道是否存在针对此问题的单行解决方案。
keras ×4
python ×4
android ×1
arrays ×1
dictionary ×1
embedding ×1
loss ×1
matplotlib ×1
pandas ×1
plot ×1
pyspark ×1
python-3.x ×1
seaborn ×1
tensor ×1
yuv ×1