tensorflow js에서 '데이터 세트에 의해 생성 된 기능 데이터에 필요한 입력 키가 없습니다'라는 오류는 무엇을 의미합니까?

Martijn

무엇 않는 오류 (약속)에 처리되지 않는 오류 : 데이터 세트에 의해 생성 된 특징 데이터가 필요한 입력 키 'dense_Dense1_input를'부족하다. 평균? 이 문제를 해결하기 위해 다른 입력 모양과 다른 배치 크기와 같은 여러 가지를 시도했지만 아무것도 작동하지 않는 것 같습니다. 484 개의 기능과 30 개의 행이있는 데이터 입력과 1 개의 열과 30 개의 행으로 설정된 레이블이 있습니다.

정확한 오류는 다음과 같습니다.

Uncaught (in promise) Error: The feature data generated by the dataset lacks the required input key 'dense_Dense1_input'.
    at new e (errors.ts:48)
    at Wd (training_dataset.ts:277)
    at Pd (training_dataset.ts:222)
    at training_dataset.ts:421
    at common.ts:14
    at Object.next (common.ts:14)
    at o (common.ts:14)

내 코드

<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>
<title>test</title>             
</head>
<body>
<script>

const csvUrlData = '/image_data.csv';
const csvUrlLabel = '/number_data.csv';
const headers_image = Array.from(Array(484).keys());
const headers_image_string = headers_image.map(String);

async function run() {
  const csvDataset = tf.data.csv(
    csvUrlData,{
        hasHeader: false,
        columnNames: headers_image_string
    });
  const csvLabelset = tf.data.csv(
    csvUrlLabel, {
        columnConfigs: {
            label_numbers: {
                isLabel: true
            }
        }
    }
  );

  const flattenedDataset = tf.data.zip({xs: csvDataset, ys: csvLabelset}).batch(5);

  const model = tf.sequential();
  model.add(tf.layers.dense({
    inputShape: [484],
    units: 1
  }));
  model.compile({
    optimizer: tf.train.sgd(0.00000001),
    loss: 'meanSquaredError'
  });

  return await model.fitDataset(flattenedDataset, {
    epochs: 10,
    callbacks: {
      onEpochEnd: async (epoch, logs) => {
        console.log(epoch + ':' + logs.loss);
      }
    }
  });
}
run();
</script>
</body>
</html>
Edkeveked

isLabel속성은 사용할 수 없습니다해야 labelDataset데이터가 이후에 압축되기 때문이다. 그러면 레이블에 대한 중첩 된 개체가 만들어집니다. map사용해야하는 경우 연산자 는의 ys속성 만 검색하는 데 사용해야 합니다 labelDataset.

  const csvDataset = tf.data.csv(
    csvUrlData,{
        hasHeader: false,
        columnNames: headers_image_string
    });
  const csvLabelset = tf.data.csv(
    csvUrlLabel, {
        columnConfigs: {
            label_numbers: {
                isLabel: true
            }
        }
    }
  );

  const flattenedcsvDataset =
    csvDataset
    .map((data) =>
      {
        return Object.values(data)
      })

  const flattenedcsvLabelset =
    csvDataset
    .map((data) =>
      {
        return Object.values(data)
      })

  const flattenedDataset = tf.data.zip({xs: flattenedcsvDataset, ys: flattenedcsvLabelset}).batch(5);

flattenedDataset다음 훈련을 위해 사용할 수 있습니다.

const csvUrl =
'https://storage.googleapis.com/tfjs-examples/multivariate-linear-regression/data/boston-housing-train.csv';

(async function run() {
 
  const csvDataset = tf.data.csv(
    csvUrl, {
      columnConfigs: {
       /* medv: {
          isLabel: true
        }*/
      }
    });

  // Number of features is the number of column names minus one for the label
  // column.
  const numOfFeatures = (await csvDataset.columnNames()).length ;

  // Prepare the Dataset for training.
  const flattenedDataset =
    csvDataset
    .map((data) =>
      {
      return Object.values(data)
      })
  
  const zip = tf.data.zip({xs: flattenedDataset, ys: flattenedDataset}).batch(10)
  
  // Define the model.
  const model = tf.sequential();
  model.add(tf.layers.dense({
    inputShape: [numOfFeatures],
    units: numOfFeatures
  }));
  model.compile({
    optimizer: tf.train.sgd(0.000001),
    loss: 'meanSquaredError'
  });

  // Fit the model using the prepared Dataset
  return model.fitDataset(zip, {
    epochs: 10,
    callbacks: {
      onEpochEnd: async (epoch, logs) => {
        console.log(epoch + ':' + logs.loss);
      }
    }
  });
})()
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>
<title>test</title>             
</head>
<body>
<script>


</script>
</body>
</html>

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관