我想在形状为tf.image.crop_and_resize
的3-D张量的图像上使用[image_height, image_width, depth]
,但tf.image.crop_and_resize
期望形状为{[batch, image_height, image_width, depth]
的4-D张量1}}。
我怎样才能暂时"不挤压"插入批量维度?
答案 0 :(得分:1)
您可以使用tf.expand_dims
将3-D
图片制作成4-D
batch size
形状的tf.image.crop_and_resize(tf.expand_dims(image, 0), ...)
。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NotePlay: MonoBehaviour
{
Button record;
public bool recordMode = false;
Animator anim;
public AudioClip noteA;
public AudioClip noteB;
public AudioClip noteC;
public AudioClip noteD;
public AudioClip noteE;
public AudioClip noteF;
public AudioClip noteG;
public AudioSource audio;
// Use this for initialization
public ArrayList notes;
void Start()
{
anim = gameObject.GetComponent<Animator>();
audio = GetComponent<AudioSource>();
notes = new ArrayList();
}
void Playback()
{
print(notes.Count);
for (int i = 0; i < notes.Count; i++)
{
char c = (char)notes[i];
System.Threading.Thread.Sleep(1000);
PlayNote(c);
}
}
void PlayNote(char note)
{
if (note == 'a')
{
//anim.SetTrigger("A");
GameObject.Find("Sphere_A").GetComponent<AudioSource>().PlayOneShot(noteA);
GameObject.Find("Sphere_A").GetComponent<Animator>().SetTrigger("A");
}
if (note == 'b')
{
//anim.SetTrigger("B");
GameObject.Find("Sphere_B").GetComponent<AudioSource>().PlayOneShot(noteB);
GameObject.Find("Sphere_B").GetComponent<Animator>().SetTrigger("B");
print("b");
}
if (note == 'c')
{
///anim.SetTrigger("C");
GameObject.Find("Sphere_C").GetComponent<AudioSource>().PlayOneShot(noteC);
}
if (note == 'd')
{
//anim.SetTrigger("D");
GameObject.Find("Sphere_D").GetComponent<AudioSource>().PlayOneShot(noteD);
}
if (note == 'e')
{
//anim.SetTrigger("E");
GameObject.Find("Sphere_E").GetComponent<AudioSource>().PlayOneShot(noteE);
}
else if (note == 'f')
{
// anim.SetTrigger("F");
GameObject.Find("Sphere_F").GetComponent<AudioSource>().PlayOneShot(noteF);
}
else if (note == 'g')
{
//anim.SetTrigger("G");
GameObject.Find("Sphere_G").GetComponent<AudioSource>().PlayOneShot(noteG);
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
recordMode = !recordMode;
}
if (recordMode == true)
{
if (Input.GetKeyDown(KeyCode.A)) { notes.Add('a'); print("a"); }
if (Input.GetKeyDown(KeyCode.B)) {notes.Add('b'); print("b"); }
if (Input.GetKeyDown(KeyCode.C)) notes.Add('c');
if (Input.GetKeyDown(KeyCode.D)) notes.Add('d');
if (Input.GetKeyDown(KeyCode.E)) notes.Add('e');
if (Input.GetKeyDown(KeyCode.F)) notes.Add('f');
if (Input.GetKeyDown(KeyCode.G)) notes.Add('g');
}
else
{
if (Input.GetKeyDown(KeyCode.P))
{
Playback();
}
}
}
}