小编csb*_*sbk的帖子

如何将numpy数组存储为tfrecord?

我正在尝试从numpy数组创建tfrecord格式的数据集.我想存储2d和3d坐标.

2d坐标是float64类型的numpy数组(2,10)3d坐标是float64类型的numpy数组(3,10)

这是我的代码:

def _floats_feature(value):
    return tf.train.Feature(float_list=tf.train.FloatList(value=value))


train_filename = 'train.tfrecords'  # address to save the TFRecords file
writer = tf.python_io.TFRecordWriter(train_filename)


for c in range(0,1000):

    #get 2d and 3d coordinates and save in c2d and c3d

    feature = {'train/coord2d': _floats_feature(c2d),
                   'train/coord3d': _floats_feature(c3d)}
    sample = tf.train.Example(features=tf.train.Features(feature=feature))
    writer.write(sample.SerializeToString())

writer.close()
Run Code Online (Sandbox Code Playgroud)

当我运行这个我得到错误:

  feature = {'train/coord2d': _floats_feature(c2d),
  File "genData.py", line 19, in _floats_feature
return tf.train.Feature(float_list=tf.train.FloatList(value=value))
  File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\google\protobuf\internal\python_message.py", line 510, in init
copy.extend(field_value)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\google\protobuf\internal\containers.py", line 275, in extend
new_values = [self._type_checker.CheckValue(elem) for elem in elem_seq_iter]
  File …
Run Code Online (Sandbox Code Playgroud)

python numpy tensorflow tfrecord

12
推荐指数
3
解决办法
5615
查看次数

如何使用grpc通过服务器在客户端之间发送消息?

我正在尝试创建一个程序,以便客户端能够相互发送消息。因此,当客户端发送消息时,该消息将被发送到服务器,服务器将其发送到接收方客户端。我遇到的问题是,如果客户端不先发送消息,服务器就无法向客户端发送消息,因此如果客户端不先发送任何内容,那么客户端如何通过服务器简单地从另一个客户端接收消息。

这是我的原型文件:

service Messenger {
    rpc SendMessage (stream Message) returns (stream Message) {}
}

message Message {
  string msg = 1;
  receiverId = 2;
}
Run Code Online (Sandbox Code Playgroud)

我还生成了类文件并编写了用于按照以下示例发送消息的客户端和服务器函数:https://github.com/grpc/grpc/blob/v1.15.0/examples/csharp/RouteGuide/RouteGuideServer/RouteGuideImpl.cs。目前,它只允许客户端向服务器发送消息。我现在正在寻找一种方法

1)从服务器发送消息到与消息中指定的receiverId具有相同id的客户端

或者

2)我听说你可以让客户以某种方式订阅来自某些客户的消息,但我找不到任何关于如何做到这一点的信息

任何帮助表示赞赏!谢谢

c# client-server protocol-buffers grpc

5
推荐指数
1
解决办法
1万
查看次数

如何画出一笔财富?

我试图使用本教程创建一个旋转游戏的游戏:

http://www.emanueleferonato.com/2015/07/31/create-a-wheel-of-fortune-for-your-html5-games-with-phaser-in-only-a-few-lines/

但是,本教程使用了轮子的图像,我想在html5/js中创建它.像这样模糊的东西:

https://www.winkbingo.com/images/lp/301114/spin_the_wheel_image.png 这是我到目前为止:

var ctx = canvas.getContext("2d");
var end = 0;
var color = ['#F0F8FF','#FAEBD7','#00FFFF','#7FFFD4','#00FF00','#FF8C00'];
var labels = ['label1', 'label2','label3','label4','label5','label6'];
var slices = 6

for (var i = 0; i < slices; i++) {
ctx.fillStyle = color[i];
ctx.beginPath();
ctx.moveTo(canvas.width/2,canvas.height/2);
ctx.arc(canvas.width/2,canvas.height/2,canvas.height/2,end, ((1/slices)*Math.PI*2)+end ,false);
ctx.lineTo(canvas.width/2,canvas.height/2);
ctx.fill();
end += ((1/slices)*Math.PI*2)+end;
}
Run Code Online (Sandbox Code Playgroud)

我希望通过更改变量切片(1-6之间)来更改段的数量.我还想在顶部显示标签.然后我想使用这个画布而不是该教程代码中的图像,以便轮子旋转文本.希望这不会令人困惑.任何人都知道如何做到这一点>我不介意使用任何库等.

html javascript html5 html5-canvas

3
推荐指数
2
解决办法
1万
查看次数

如何将tfrecord数据读入张量/ numpy数组?

我有一个tfrecord文件,我存储了一个数据列表,每个元素有2d坐标和3d坐标.坐标是dtype float64的2d numpy数组.

这些是我用来存储它们的功能.

feature = {'train/coord2d': _floats_feature(projC),
                   'train/coord3d': _floats_feature(sChair)}
Run Code Online (Sandbox Code Playgroud)

我把它们压平成一个浮动列表来存储它们.

def _floats_feature(value):
    return tf.train.Feature(float_list=tf.train.FloatList(value=value.flatten()))
Run Code Online (Sandbox Code Playgroud)

现在我正在努力收听它们,以便我可以将它们送入我的网络来训练它.我想要2d coords作为输入,3d要成为训练我的netwrok的输出.

def read_and_decode(filename):
    filename_queue = tf.train.string_input_producer(filename, name='queue')
    reader = tf.TFRecordReader()
    _, serialized_example = reader.read(filename_queue)
    features = tf.parse_single_example(
    serialized_example,

    features= {'train/coord2d': tf.FixedLenFeature([], tf.float32),
            'train/coord3d': tf.FixedLenFeature([], tf.float32)})

    coord2d = tf.cast(features['train/coord2d'], tf.float32)
    coord3d = tf.cast(features['train/coord3d'], tf.float32)

    return coord2d, coord3d



with tf.Session() as sess:
    filename = ["train.tfrecords"]
    dataset = tf.data.TFRecordDataset(filename)
    c2d, c3d = read_and_decode(filename)
   print(sess.run(c2d))
   print(sess.run(c3d))
Run Code Online (Sandbox Code Playgroud)

这是我的代码,但我真的不明白,因为我从教程等得到它所以我试图打印出c2d和c3d,看看他们的格式,但我的程序只是保持运行,并没有打印任何东西,永远不会终止.c2d和c3d是否包含数据集中每个元素的2d和3d坐标?在将网络作为输入和输出进行培训时,它们可以直接使用吗?

在将它们用作网络输入之前,我也不知道它们应该是什么格式.我应该将它们转换回2d numpy数组或2d张量?在哪种情况下我该怎么办?整体而言我只是非常失落,所以任何guidace都会非常有帮助!谢谢

python neural-network tensorflow

1
推荐指数
1
解决办法
2201
查看次数