所以我通过以下代码让我的keras模型与tf.Dataset一起工作:
# Initialize batch generators(returns tf.Dataset)
batch_train = build_features.get_train_batches(batch_size=batch_size)
# Create TensorFlow Iterator object
iterator = batch_train.make_one_shot_iterator()
dataset_inputs, dataset_labels = iterator.get_next()
# Create Model
logits = .....(some layers)
keras.models.Model(inputs=dataset_inputs, outputs=logits)
# Train network
model.compile(optimizer=train_opt, loss=model_loss, target_tensors=[dataset_labels])
model.fit(epochs=epochs, steps_per_epoch=num_batches, callbacks=callbacks, verbose=1)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试将validation_data参数传递给模型时.适合它告诉我,我不能用它与发电机.有没有办法在使用tf.Dataset时使用验证
例如在tensorflow中,我可以执行以下操作:
# initialize batch generators
batch_train = build_features.get_train_batches(batch_size=batch_size)
batch_valid = build_features.get_valid_batches(batch_size=batch_size)
# create TensorFlow Iterator object
iterator = tf.data.Iterator.from_structure(batch_train.output_types,
batch_train.output_shapes)
# create two initialization ops to switch between the datasets
init_op_train = iterator.make_initializer(batch_train)
init_op_valid = iterator.make_initializer(batch_valid) …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 3D 浮点列表写入 TFrecord,因此我成功地通过先将其展平来编写它,然后对其进行解析,但在对其进行整形时会引发错误。
错误: ValueError: Shapes () and (8,) are not compatible
这就是我编写 TFrecord 文件的方式
def _floats_feature(value):
return tf.train.Feature(float_list=tf.train.FloatList(value=value.flatten()))
def write(output_path, data_rgb, data_depth, data_decalib):
with tf.python_io.TFRecordWriter(output_path) as writer:
feature = {'data_rgb': _floats_feature(data_rgb),
'data_depth': _floats_feature(data_depth),
'data_decalib': _floats_feature(data_decalib)}
sample = tf.train.Example(features=tf.train.Features(feature=feature))
writer.write(sample.SerializeToString())
Run Code Online (Sandbox Code Playgroud)
这就是我读取 TFrecord 文件的方式
def get_batches(date, drives, batch_size=1):
"""
Create a generator that returns batches of tuples
rgb, depth and calibration
:param date: date of the drive
:param drives: array of the drive_numbers within the drive date
:return: batch generator …Run Code Online (Sandbox Code Playgroud) 我有一个本地代理服务127.0.0.1:8080
我可以用它进行 api 调用,但不能在 django 中调用,由于某种原因,它可以在常规 python 代码(即python test.py)中工作,但不能在 django 中工作。
import requests
proxies = {
'http': 'http://127.0.0.1:8080',
'https': 'https://127.0.0.1:8080',
}
response = requests.get('https://api.ipify.org?format=json', proxies=proxies)
Run Code Online (Sandbox Code Playgroud)
Djangov3.0.8和请求v2.24.0
我假设 WSGI 以某种方式覆盖我的代理设置
错误
HTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: /?format=json (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa922093340>: Failed to establish a new connection: [Errno 111] Connection refused')))
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个非常简单的函数,它接受一个列表(例如:) [1,2,3,1,5]并返回一个直接在特定元素之后的元素列表.
到目前为止我所得到的是:
function element list = filter (\x -> element:x) list
Run Code Online (Sandbox Code Playgroud)
我想要的输出:
功能1 [1,2,3,1,5]
=> [2,5]