Using package github.com/abema/go-mp4 when i try to run the example in the docs i get following error:
invalid operation: box (variable of type *mp4.BoxInfo) is not an interface
Here is the example that i am trying:
// extract specific boxes
boxes, err := mp4.ExtractBox(file, nil, mp4.BoxPath{mp4.BoxTypeMoov(), mp4.BoxTypeTrak(), mp4.BoxTypeTkhd()})
if err != nil {
:
}
for _, box := range boxes {
tkhd := box.(*mp4.Tkhd)
fmt.Println("track ID:", tkhd.TrackID)
}
https://pkg.go.dev/github.com/abema/go-mp4#section-readme
Sorry, it is an error of my sample code.
I created Pull Request to fix it.
https://github.com/abema/go-mp4/pull/113/files
When you find any other problems about go-mp4, I would be grateful if you could create new Issue on GitHub.
https://github.com/abema/go-mp4/issues
Related
I'm trying to use the K8S Go client to list the ClusterServiceVersions.
It could be enough to have the raw response body.
I've tried this:
data, err := clientset.RESTClient().Get().Namespace(namespace).
Resource("ClusterServiceVersions").
DoRaw(context.TODO())
if err != nil {
panic(err.Error())
}
fmt.Printf("%v", string(data))
But it returns the following error:
panic: the server could not find the requested resource (get ClusterServiceVersions.meta.k8s.io)
How do I specify to use the operators.coreos.com group?
Looking at some existing code I've also tried to add
VersionedParams(&v1.ListOptions{}, scheme.ParameterCodec)
But it result in this other error:
panic: v1.ListOptions is not suitable for converting to "meta.k8s.io/v1" in scheme "pkg/runtime/scheme.go:100"
It is possible to do a raw request using the AbsPath() method.
path := fmt.Sprintf("/apis/operators.coreos.com/v1alpha1/namespaces/%s/clusterserviceversions", namespace)
data, err := clientset.RESTClient().Get().
AbsPath(path).
DoRaw(ctx)
Also notice that if you want to define clientset using the interface (kubernetes.Interface) instead of the concrete type (*kubernetes.Clientset) the method clientset.RESTClient() is not directly accessible, but you can use the following one:
clientset.Discovery().RESTClient()
When I'm using the rpcclient to get a new address for the account 'default',running the code below.
client.WalletPassphrase("test1",600)
address,err:=client.GetNewAddress("default")
addresses,err :=client.GetAddressesByAccount("default")
fmt.Println(address)
fmt.Println(addresses)
The output is
<nil>
[]
When I use the command line "btcctl --simnet --rpcuser=rpcuser --rpcpass=rpcpass --wallet getaddressesbyaccount default".It actually output the addresses.
btcctl --simnet --rpcuser=rpcuser --rpcpass=rpcpass --wallet getaddressesbyaccount default
[
"SY2R4vpLPvucTC4MZX1FEEAdX917FZps1H",
"SfBUHVbQ2FRqWPe9wHJuJx2yUstHgRbyBi",
"SehRVnJnhqQ8QeRBgB3B92WZTGo3s9hyCi",
"SUPkJTmx9EjiSMb6qsoSmjShzrejEkhjgn",
"SXu8VAv1cKqC5dkJqredVuhzgzD8QVQvQt",
"SXm73AFZfMqUpCUvEwjdhFxDAwFyD3WVfZ",
"SgN9K7kEsvWgpSzaP4ZZTYaomQfLyYqdkF",
"SUKk1E1JR7wGNTdzLtkb7xJmWN8UgAGdH8",
"SSqpybNox5qXwsDcax8xnA3JqaUqYEzzTq",
"SNpyvoZSEHudpBC4bogkbySioh6HddpEie",
"SimTTUz59RytXsXpTGYwaCqgomiGY8egpo",
"SW9vY6YfJYtHspqVfpijyoi548XXqfrHtt",
"SXJXnLyxYwL2BG8pcAZgW4HCB5ZVCrsS3G",
"SRna6gpPf6bqdfvrmCZz5dzfU9qNbnMZvF",
"SZTUE5WK4EPnF9899a8p5htjpdK9ocN16d",
"Sk2CH4gy9Jhv1wW5YwZzgZmNPgPoHdeYML",
"SkBZ2bTdtYykfE7fSRUc3vAM6w1ub3vTbq"
]
So how can I get the these addresses in my golang function?
I would recommand you in each step check the error and log it to see what is the exact error:
( do not forget to import log)
something like the following code could help you what is the error.
client.WalletPassphrase("test1",600)
address,err:=client.GetNewAddress("default")
if err != nil {
log.Fatal(err)
}
addresses,err :=client.GetAddressesByAccount("default")
if err != nil {
log.Fatal(err)
}
fmt.Println(address)
fmt.Println(addresses)
Python code of train model:
input_schema = dataset_schema.from_feature_spec({
REVIEW_COLUMN: tf.FixedLenFeature(shape=[], dtype=tf.string),
LABEL_COLUMN: tf.FixedLenFeature(shape=[], dtype=tf.int64)
})
In python predictions work fine. Example of client:
loaded_model = tf.saved_model.loader.load(sess, ["serve"], '/tmp/model/export/Servo/1506084916')
input_dict, output_dict =_signature_def_to_tensors(loaded_model.signature_def['default_input_alternative:None'])
start = datetime.datetime.now()
out = sess.run(output_dict, feed_dict={input_dict["inputs"]: ("I went and saw this movie last night",)})
print(out)
print("Time all: ", datetime.datetime.now() - start)
But golang client does not work:
m, err := tf.LoadSavedModel("/tmp/model/export/Servo/1506084916", []string{"serve"}, &tf.SessionOptions{})
if err != nil {
panic(fmt.Errorf("load model: %s", err))
}
data := "I went and saw this movie last night"
t, err := tf.NewTensor([]string{data})
if err != nil {
panic(fmt.Errorf("tensor err: %s", err))
}
fmt.Printf("tensor: %v", t.Shape())
output, err = m.Session.Run(
map[tf.Output]*tf.Tensor{
m.Graph.Operation("save_1/StringJoin/inputs_1").Output(0): t,
}, []tf.Output{
m.Graph.Operation("linear/binary_logistic_head/predictions/classes").Output(0),
}, nil,
)
if err != nil {
panic(fmt.Errorf("run model: %s", err))
}
I got error:
panic: run model: You must feed a value for placeholder tensor
'Placeholder' with dtype string and shape [?]
[[Node: Placeholder = Placeholder_output_shapes=[[?]], dtype=DT_STRING, shape=[?],
_device="/job:localhost/replica:0/task:0/cpu:0"]]
How can I present shape=[?] tensor with golang? Or I need to change input format of python training script?
UPD:
This string "save_1/StringJoin/inputs_1" I received after running this python-code:
for n in sess.graph.as_graph_def().node:
if "inputs" in n.name:
print(n.name)
Output:
transform/transform/inputs/review/Placeholder
transform/transform/inputs/review/Identity
transform/transform/inputs/label/Placeholder
transform/transform/inputs/label/Identity
transform/transform_1/inputs/review/Placeholder
transform/transform_1/inputs/review/Identity
transform/transform_1/inputs/label/Placeholder
transform/transform_1/inputs/label/Identity
save_1/StringJoin/inputs_1
save_2/StringJoin/inputs_1
The error tells you You must feed a value for placeholder tensor 'Placeholder': this means that the graph can't be built until you feed a value for that placeholder.
In your python code, your feed it at the line:
input_dict["inputs"]: ("I went and saw this movie last night",)
In fact, input_dict["inputs"] is evaluated to: <tf.Tensor 'Placeholder:0' shape=(?,) dtype=string>.
In your Go code, instead, you're looking for a tensor named save_1/StringJoin/inputs_1 that's not the placeholder.
The rule to follow is: use the same input both in Python & Go.
To solve the problem, thus, you just have to extract from the graph the placeholder named Placeholder (just like in python) and then use it.
m.Graph.Operation("Placeholder").Output(0): t,
Also, I suggest you to use a more complete and easy to use wrapper around the tensorflow API: tfgo
One more thing. I read TF docs and found this topic
It helps to find correct input/output keys, example of response:
The given SavedModel SignatureDef contains the following input(s): inputs['inputs'] tensor_info:
dtype: DT_STRING
shape: (-1)
name: Placeholder:0
PS/ Posted as answer for focusing
I'm running http request in golang
resp, err := client.Do(req)
if err != nil {
return "", err
}
So, it returns error back to the main function, that attempts to store it in the database:
_, err = db.Exec("UPDATE test SET error = $1 WHERE id = $2", error, id)
I receive the following error: sql: converting Exec argument #1's type: unsupported type errors.errorString, a struct exit status 1
So, I understand, that error has a different type, but I can't find information on how to pass the value of the error to the string. Could someone direct me in a right way.
Use the function:
error.Error()
to get a string representation of the error.
Tip: avoid naming variables with existing type names. error is a type name and it's also your variable name, which might lead to confusion.
I'm trying to make a really simple ssh address book program. Takes some info about ssh addresses and stores them in a yaml document. I'm doing it partly to learn a bit about Go and am having a small problem. I can serialize the data and put a document into a file but I'm getting this error when I try to read it back:
yaml: control characters are not allowed
I'm not sure what this error message means, googling didn't yield any helpful results. Any ideas?
These are the structs I'm using to organize the data:
type EntriesList struct {
SSHEntries []SSHEntry `yaml:"sshentries"`
}
type SSHEntry struct {
Name string `yaml:"name"`
Command SSHCmd `yaml:"command"`
}
type SSHCmd struct {
Addr string `yaml:"addr"`
Port int `yaml:"port"`
Uname string `yaml:"uname"`
}
The format it puts my data into is:
---
entrieslist:
- name: entry1
command:
addr: somewhere
port: 22
uname: someone
- name: entry2 ... etc
I checked this ^^ with a YAML validator and it is legal YAML.
Here is my function to read the file:
// CONF is the path to the file
func readConf(CONF string) *EntriesList {
configFile := openConfigFile(CONF)
defer configFile.Close()
buffer := make([]byte, 512, 512)
_, err := configFile.Read(buffer)
check(err)
var entries EntriesList
err = yaml.Unmarshal(buffer, &entries)
data, _ := yaml.Marshal(entries)
fmt.Println(string(data))
return &entries
}
Figured it out, the problem was that my buffer was too big. If you have a []byte that is too big then go-yaml will read those extra bytes as characters and throw errors. I changed my code to :
func readConf(CONF string) *EntriesList {
confiFile, err := ioutil.ReadFile(CONF)
check(err)
var entries EntriesList
err = yaml.Unmarshal(confiFile, &entries)
check(err)
return &entries
}
And it worked as expected.
From the sounds of it, you're hitting the error block at https://github.com/go-yaml/yaml/blob/53feefa2559fb8dfa8d81baad31be332c97d6c77/readerc.go#L347 , and it looks like that should also be telling you the offset (where in the file it's hitting the problematic character) and character code. If that info is enough to solve your problem, then great. If, on the other hand, the yaml library is spitting out validated yaml that it is not comfortable accepting as input, you should open an issue with the maintainer on Github at https://github.com/go-yaml/yaml/issues
I know this came over-late, but using the function from the main question, one can also use the number of bytes read into the buffer to slice the data.
// CONF is the path to the file
func readConf(CONF string) *EntriesList {
configFile := openConfigFile(CONF)
defer configFile.Close()
buffer := make([]byte, 512, 512)
n, err := configFile.Read(buffer)
check(err)
var entries EntriesList
err = yaml.Unmarshal(buffer[:n], &entries)
data, _ := yaml.Marshal(entries)
fmt.Println(string(data))
return &entries
}