You've already forked LuckyWorld
FT - Write Jsonl file
This commit is contained in:
Binary file not shown.
@ -243,7 +243,7 @@ bool ULuckyDataTransferSubsystem::WriteImageToDisk(const double Timestamp, const
|
|||||||
);
|
);
|
||||||
|
|
||||||
// TODO This logs 1, it doesn't work?
|
// TODO This logs 1, it doesn't work?
|
||||||
UE_LOG(LogTemp, Warning, TEXT("Logged pixels: %d"), OutPixels.Num())
|
// UE_LOG(LogTemp, Warning, TEXT("Logged pixels: %d"), OutPixels.Num())
|
||||||
|
|
||||||
FImageWriteTask* ImageTask = new FImageWriteTask();
|
FImageWriteTask* ImageTask = new FImageWriteTask();
|
||||||
|
|
||||||
@ -270,7 +270,7 @@ bool ULuckyDataTransferSubsystem::WriteImageToDisk(const double Timestamp, const
|
|||||||
|
|
||||||
UE_LOG(LogTemp, VeryVerbose, TEXT("FileName %s"), *Filename);
|
UE_LOG(LogTemp, VeryVerbose, TEXT("FileName %s"), *Filename);
|
||||||
|
|
||||||
ImageTask->Format = EImageFormat::PNG;
|
ImageTask->Format = EImageFormat::JPEG;
|
||||||
ImageTask->Filename = Filename;
|
ImageTask->Filename = Filename;
|
||||||
ImageTask->PixelData = MakeUnique<TImagePixelData<FColor>>(FIntPoint(Sensor->RenderTarget->GetSurfaceWidth(), Sensor->RenderTarget->GetSurfaceHeight()), TArray64<FColor>(OutPixels));
|
ImageTask->PixelData = MakeUnique<TImagePixelData<FColor>>(FIntPoint(Sensor->RenderTarget->GetSurfaceWidth(), Sensor->RenderTarget->GetSurfaceHeight()), TArray64<FColor>(OutPixels));
|
||||||
ImageTask->bOverwriteFile = true;
|
ImageTask->bOverwriteFile = true;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "Dom/JsonObject.h"
|
#include "Dom/JsonObject.h"
|
||||||
#include "Serialization/JsonWriter.h"
|
#include "Serialization/JsonWriter.h"
|
||||||
#include "Serialization/JsonSerializer.h"
|
#include "Serialization/JsonSerializer.h"
|
||||||
|
#include "_Utils/FileUtils.h"
|
||||||
|
|
||||||
UEpisodeSubSystem::UEpisodeSubSystem()
|
UEpisodeSubSystem::UEpisodeSubSystem()
|
||||||
{
|
{
|
||||||
@ -57,9 +58,11 @@ void UEpisodeSubSystem::Tick(float DeltaTime)
|
|||||||
if (DataTransfer) DataTransfer->WriteImageToDisk(CurrentRobot->PhysicsSceneProxy->GetMujocoData().time);
|
if (DataTransfer) DataTransfer->WriteImageToDisk(CurrentRobot->PhysicsSceneProxy->GetMujocoData().time);
|
||||||
EpisodeFrames++;
|
EpisodeFrames++;
|
||||||
|
|
||||||
if (bIsEpisodeCompleted && CapturedEpisodes <= EpisodesToCapture)
|
if (!bIsEpisodeCompleted) return;
|
||||||
{
|
|
||||||
EndEpisode();
|
EndEpisode();
|
||||||
|
if (CapturedEpisodes < EpisodesToCapture)
|
||||||
|
{
|
||||||
StartEpisode();
|
StartEpisode();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -122,6 +125,7 @@ void UEpisodeSubSystem::StartTraining(const int32 EpisodesCountIn, FString BaseI
|
|||||||
void UEpisodeSubSystem::EndTraining()
|
void UEpisodeSubSystem::EndTraining()
|
||||||
{
|
{
|
||||||
StopTicking();
|
StopTicking();
|
||||||
|
CreateEpisodesStatsJsonFile();
|
||||||
// Create jsonl files
|
// Create jsonl files
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,9 +142,6 @@ void UEpisodeSubSystem::StartEpisode()
|
|||||||
RobotTransform.GetLocation() + RobotTransform.GetRotation().GetForwardVector() * HardCodedRewardDistanceFromRobotPivot * (FMath::RandBool() ? 1 : -1)
|
RobotTransform.GetLocation() + RobotTransform.GetRotation().GetForwardVector() * HardCodedRewardDistanceFromRobotPivot * (FMath::RandBool() ? 1 : -1)
|
||||||
};
|
};
|
||||||
|
|
||||||
// DrawDebugLine(this->GetWorld(), EpisodeRewardZone.GetLocation() + FVector::UpVector * 70, EpisodeRewardZone.GetLocation(), FColor::Red, true);
|
|
||||||
// DrawDebugLine(this->GetWorld(), RobotTransform.GetLocation() + FVector::UpVector * 70, RobotTransform.GetLocation(), FColor::Blue, true);
|
|
||||||
|
|
||||||
// Ask the bot to give a reachable location for the Training Object Transform
|
// Ask the bot to give a reachable location for the Training Object Transform
|
||||||
EpisodeObjectBaseTransform = CurrentRobot->RobotPilotComponent->GetReachableTransform();
|
EpisodeObjectBaseTransform = CurrentRobot->RobotPilotComponent->GetReachableTransform();
|
||||||
|
|
||||||
@ -276,7 +277,7 @@ void UEpisodeSubSystem::CreateEpisodeStatJsonLine(const FTrainingEpisodeData& Tr
|
|||||||
|
|
||||||
// Serialize into FString
|
// Serialize into FString
|
||||||
FString Output;
|
FString Output;
|
||||||
const TSharedRef<TJsonWriter<>> Writer = TJsonWriterFactory<>::Create(&Output);
|
const TSharedRef< TJsonWriter< TCHAR, TCondensedJsonPrintPolicy<TCHAR> > > Writer = TJsonWriterFactory< TCHAR, TCondensedJsonPrintPolicy<TCHAR> >::Create(&Output);
|
||||||
FJsonSerializer::Serialize(Root.ToSharedRef(), Writer);
|
FJsonSerializer::Serialize(Root.ToSharedRef(), Writer);
|
||||||
EpisodeStatLines.Add(Output);
|
EpisodeStatLines.Add(Output);
|
||||||
}
|
}
|
||||||
@ -294,6 +295,7 @@ void UEpisodeSubSystem::ConvertImagesToVideo()
|
|||||||
void UEpisodeSubSystem::CreateEpisodesStatsJsonFile()
|
void UEpisodeSubSystem::CreateEpisodesStatsJsonFile()
|
||||||
{
|
{
|
||||||
// TODO Do not use FJsonObject - simply concat the FStrings into a file
|
// TODO Do not use FJsonObject - simply concat the FStrings into a file
|
||||||
|
UFileUtils::WriteJsonlFile(EpisodeStatLines, FPaths::ProjectSavedDir(), FString("episodes_stats"));
|
||||||
|
|
||||||
// Create a jsonl file and store in the correct directory
|
// Create a jsonl file and store in the correct directory
|
||||||
// concat TArray<FString> EpisodeStatLines into a single file
|
// concat TArray<FString> EpisodeStatLines into a single file
|
||||||
|
24
Source/LuckyWorldV2/Private/_Utils/FileUtils.cpp
Normal file
24
Source/LuckyWorldV2/Private/_Utils/FileUtils.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include "_Utils/FileUtils.h"
|
||||||
|
#include "Misc/FileHelper.h"
|
||||||
|
#include "Misc/Paths.h"
|
||||||
|
|
||||||
|
UFileUtils::UFileUtils()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool UFileUtils::WriteJsonlFile(const TArray<FString>& JsonLines, const FString& BasePath, const FString& FileName)
|
||||||
|
{
|
||||||
|
// Ensure the directory exists
|
||||||
|
IFileManager::Get().MakeDirectory(*BasePath, true);
|
||||||
|
|
||||||
|
// Construct the full file path
|
||||||
|
const FString FullFilePath = FPaths::Combine(BasePath, FileName + TEXT(".jsonl"));
|
||||||
|
|
||||||
|
// Join the array into one string with line breaks
|
||||||
|
const FString FileContent = FString::Join(JsonLines, TEXT(""));
|
||||||
|
|
||||||
|
// Write to file
|
||||||
|
return FFileHelper::SaveStringToFile(FileContent, *FullFilePath);
|
||||||
|
}
|
14
Source/LuckyWorldV2/Public/_Utils/FileUtils.h
Normal file
14
Source/LuckyWorldV2/Public/_Utils/FileUtils.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "FileUtils.generated.h"
|
||||||
|
|
||||||
|
UCLASS()
|
||||||
|
class LUCKYWORLDV2_API UFileUtils : public UObject
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
UFileUtils();
|
||||||
|
|
||||||
|
static bool WriteJsonlFile(const TArray<FString>& JsonLines, const FString& BasePath, const FString& FileName);
|
||||||
|
};
|
Reference in New Issue
Block a user